简体   繁体   English

浏览器崩溃后保持自动重新加载? (JavaScript的)

[英]Keep auto reload working after browser crash? (javascript)

I made an auto reload script which continuously refreshes a webpage 1 second after the page is completely loaded. 我制作了一个自动重新加载脚本,在页面完全加载后1秒钟不断刷新网页。 It doesn't seem to be too fast, but Chrome will always crash after a while: 它似乎不是太快,但Chrome会在一段时间后崩溃:

"Aw Snap! Something went wrong while displaying this webpage. To continue, reload or go to another page." “Aw Snap!显示此网页时出现问题。继续,重新加载或转到另一页。” This is the message I get. 这是我得到的信息。 It seems the auto-reload script then stops working. 似乎自动重装脚本停止工作。

How do I get the script to keep going even after a browser crash? 如何让脚本在浏览器崩溃后继续运行?

Thanks 谢谢

PS: my current script: PS:我目前的剧本:

    if (window.location.toString() === 'http://blabla.com/wut')
    {
        setTimeout(function (){
                               window.location.reload(true);
                              },1000);
    }

there's no way, at least not with javascript, and this seems really stupid 没有办法,至少没有javascript,这看起来真的很愚蠢

browser crash = no more code is executed 浏览器崩溃=不再执行代码

You should not reload the page in that way to prevent a browser crash. 您不应该以这种方式重新加载页面以防止浏览器崩溃。 Instead use something like JQuery to download the dynamic content in a loop from a endpoint that only serves the changed content. 而是使用类似JQuery的东西从仅提供更改内容的端点循环下载动态内容。 It will save allot of data because you can drop allot of headers and unnecessary tags as well as not have to load the CSS and other resources again. 它将节省大量数据,因为您可以删除分配标题和不必要的标记,也不必再次加载CSS和其他资源。 Another programmatical answer is to use a browser extension. 另一个程序化的答案是使用浏览器扩展。

After including the JQuery library, you could preform a request like this. 在包含JQuery库之后,您可以预先形成这样的请求。

$.get( "a-dynamic-page-source.php", function( data ) {
  document.getElementById('dynamic-content').innerHTML = data;
});

You should probably be using ajax instead to do this. 您可能应该使用ajax来执行此操作。 Constantly reloading a page is usually not a good idea. 不断重新加载页面通常不是一个好主意。 In addition, there is no way around the bug. 另外,没有办法绕过这个bug。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM