Javascript window.location.reload是否完成?
我打电话Javascript window.location.reload是否完成?,javascript,windows,reload,Javascript,Windows,Reload,我打电话 在javascript方法中更新页面。在这个调用之后,我还有其他javascript调用。有没有办法知道window.location.reload(false)在调用其他javascript调用之前何时已完成运行?您的代码行window.location.reload(false)会导致浏览器重新加载当前页面-此语句之后不会执行任何脚本 您可以在第一次加载时设置cookie,然后在后续加载时检查cookie是否存在并执行操作。。。伪代码: window.location.reload
在javascript方法中更新页面。在这个调用之后,我还有其他javascript调用。有没有办法知道window.location.reload(false)在调用其他javascript调用之前何时已完成运行?您的代码行
window.location.reload(false)
会导致浏览器重新加载当前页面-此语句之后不会执行任何脚本
您可以在第一次加载时设置cookie,然后在后续加载时检查cookie是否存在并执行操作。。。伪代码:
window.location.reload(false)
您可以检查cookie上的时间,并选择在一段时间(例如1小时)过后执行该函数。…您只需提供一个函数来加载:重载与加载没有什么不同
onload = check cookie
if cookie is present
run function
else
set cookie
reload
我使用hashtag设置变量,告诉我页面是否重新加载。你可以这样做:
window.onload = function() { // ...
//获取页面的哈希值
var hashstring=window.location.hash.substring(1);
var=false;
//是否存在哈希?
如果(hashstring.length>0)
{
//用“&”符号分割散列(以防散列中有更多变量,就像我一样)
var a=hashstring.split(&);
//循环遍历这些值
对于(i=0;i
我已经在我的项目中将在散列中查找变量的代码放在一个单独的函数中,但为了简单起见,我只是在上面添加了它。这使得确定页面是否已重新加载成为可能,并且仅当页面已重新加载时才运行代码。您必须将其他js调用放入函数中,并在页面重新加载后调用它
// Get the hash of the page
var hashstring = window.location.hash.substring(1);
var found = false;
// Do a hash exist?
if (hashstring.length > 0)
{
// Split the hash by '&'-sign (in case you have more variables in the hash, as I have)
var a = hashstring.split("&");
// Loop through the values
for (i = 0; i < a.length; i++)
{
// Split the string by '=' (key=value format)
var b = a[i].split("=");
// If the key is 'reloaded' (which tells us if the page is reloaded)
if(b[0] == 'reloaded')
{
found = true;
}
}
}
if(!found)
{
location.hash = 'reloaded=true';
window.location.reload();
}
// Do other stuff, this will only be executed if the page has been reloaded