使用jQuery刷新(重新加载)页面一次? [英] Refresh (reload) a page once using jQuery?

查看:1284
本文介绍了使用jQuery刷新(重新加载)页面一次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm wondering how to refresh/reload a page (or even specific div) once(!) using jQuery?

理想情况是在DOM structure可用后立即发生(参见onload事件),并且不会对back buttonbookmark功能产生负面影响.

Ideally in a way right after the DOM structure is available (cf. onload event) and not negatively affecting back button or bookmark functionality.

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

Please, note: replace() is not allowed due to third-party restrictions.

推荐答案

好的,我想我明白了您的要求.试试这个

Alright, I think I got what you're asking for. Try this

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.
}


如果是一次,那就去做


If it is once, then just do

$('#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内容将刷新一次.比刷新整个页面要好.

So, every five seconds the div #div-id content will refresh. Better than refreshing the whole page.

这篇关于使用jQuery刷新(重新加载)页面一次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆