php jq如何刷新当前页面,使用jQuery刷新(重新加载)一次页面?

使用jQuery刷新(重新加载)一次页面?

我想知道如何使用jQuery刷新/重新加载页面(甚至特定div)一次(!)?

理想情况下,在replace()可用之后(参见onload事件)并且不会对back button或bookmark功能产生负面影响。

请注意:由于第三方限制,不允许使用replace()。

14个解决方案

78 votes

好吧,我想我得到了你所要求的。 试试这个

if(window.top==window) {

// You're not in a frame, so you reload the site.

window.setTimeout('location.reload()', 3000); //Reloads after three seconds

}

else {

//You're inside a frame, so you stop reloading.

}

如果它是一次,那就做

$('#div-id').triggerevent(function(){

$('#div-id').html(newContent);

});

如果是定期的

function updateDiv(){

//Get new content through Ajax

...

$('#div-id').html(newContent);

}

setInterval(updateDiv, 5000); // That's five seconds

因此,div#div-id内容每五秒钟刷新一次。 比刷新整个页面更好。

Ben answered 2019-04-12T01:21:57Z

66 votes

要重新加载,您可以尝试这样做:

window.location.reload(true);

Milli answered 2019-04-12T01:22:24Z

40 votes

window.location.href=window.location.href;

Maz answered 2019-04-12T01:22:42Z

4 votes

$('#div-id').click(function(){

location.reload();

});

这是正确的语法。

$('#div-id').html(newContent); //This doesnt work

swapnil answered 2019-04-12T01:23:07Z

4 votes

用这个:

$(document).ready(function(){

// Check if the current URL contains '#'

if(document.URL.indexOf("#")==-1)

{

// Set the URL to whatever it was plus "#".

url = document.URL+"#";

location = "#";

//Reload the page

location.reload(true);

}

});

由于if条件,页面将仅重新加载一次。

Parag Gaiwkad answered 2019-04-12T01:23:39Z

3 votes

您没有jQuery刷新功能,因为这是JavaScript基础知识。

试试这个:

Adrian P. answered 2019-04-12T01:24:08Z

2 votes

使用:

Reload (Refresh) Page Using Jquery

$(document).ready(function () {

$('#reload').click(function() {

window.location.reload();

});

});

Reload (Refresh) Page Using

Vicky answered 2019-04-12T01:24:29Z

1 votes

将其添加到文件的顶部,该网站将每30秒刷新一次。

window.onload = Refresh;

function Refresh() {

setTimeout("refreshPage();", 30000);

}

function refreshPage() {

window.location = location.href;

}

另一个是:添加头标签

Paresh3489227 answered 2019-04-12T01:25:04Z

1 votes

- location = location

- location = location.href

- location = window.location

- location = self.location

- location = window.location.href

- location = self.location.href

- location = location['href']

- location = window['location']

- location = window['location'].href

- location = window['location']['href']

你不需要jQuery。 你可以用JavaScript做到这一点。

Steve answered 2019-04-12T01:25:46Z

0 votes

请改用它

function timedRefresh(timeoutPeriod) {

setTimeout("location.reload(true);",timeoutPeriod);

}

image

arunav answered 2019-04-12T01:26:14Z

0 votes

试试这段代码:

$('#iframe').attr('src', $('#iframe').attr('src'));

Koss answered 2019-04-12T01:26:35Z

0 votes

试试这个:

user1016195 answered 2019-04-12T01:26:55Z

0 votes

要使用javascript刷新页面,您只需使用:

location.reload();

Felipe Leão answered 2019-04-12T01:27:21Z

0 votes

您可能需要使用this参考以及location.reload()检查一下,它会起作用。

this.location.reload();

Tino Jose Thannippara answered 2019-04-12T01:27:48Z

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值