如何使浏览器自动重新加载或刷新 [英] How to make Browser auto reload or refresh
本文介绍了如何使浏览器自动重新加载或刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果网页不可用或无法连接
则浏览器自动重新加载/刷新。
我是已经尝试使用插件或javascript但仍然无法正常工作。
if "Webpage is not available" or "Unable to connect"
then browser auto relaod/refresh.
i'm already try using plugin or javascript but still not working properly.
推荐答案
这必须是浏览器的插件,因为,如果页面没有加载,如果不可用,你的javascript也不会自动刷新页面。
你必须为你想支持的每个浏览器编写一个插件。
This has to be a plugin for the browser since, well, if the page doesn't load, neither does your javascript to automatically refresh the page if not available.
You'd have to write a plugin for each browser you want to support.
以下是检查网页是否使用JavaScript连接的方法:http://www.kirupa.com/html5/check_if_internet_connection_exists_in_javascript.htm。这个问题很好解释,你应该看一下。
Here is how to check if web page is connected in JavaScript: http://www.kirupa.com/html5/check_if_internet_connection_exists_in_javascript.htm. This is well explained and you should take a look.
//I added the location.reload() if connection fails.
function doesConnectionExist()
{
var xhr = new XMLHttpRequest();
var file = "http://www.yoursite.com/somefile.png";
var randomNum = Math.round(Math.random() * 10000);
xhr.open('HEAD', file + "?rand=" + randomNum, false);
try
{
hr.send();
if (xhr.status >= 200 && xhr.status < 304)
{
return true;
}
else
{
return false;
location.reload();
}
}
catch (e)
{
return false;
}
}
这篇关于如何使浏览器自动重新加载或刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文