[英]javascript back button showing event listener call?
I have a javascript event listener function that waits for a user to click on any link then shows a loading box then progresses onto next page. 我有一个javascript事件监听器函数,它等待用户单击任何链接,然后显示一个加载框,然后进入下一页。
If a user then clicks the back button it still shows the loading box? 如果用户随后单击“后退”按钮,它仍然显示加载框? Is there a way I can remove it without having to force refresh?
有没有一种方法可以删除它而不必强制刷新?
function loading_show() {
document.getElementById("loading").removeAttribute("style");
}
// Function to add event listener to t
function load() {
var el = document.getElementsByTagName("a");
for (var i = 0; i < el.length; i++)
{
el[i].addEventListener("click", loading_show, false);
}
}
function init() {
// quit if this function has already been called
if (arguments.callee.done) return;
// flag this function so we don't do the same thing twice
arguments.callee.done = true;
// do stuff
load();
};
var _timer = setInterval(function() {
if (/loaded|complete/.test(document.readyState)) {
clearInterval(_timer);
init(); // call the onload handler
}
}, 10);
PS. PS。 I'm developing for a mobile environment and I don't wish to use jQuery so don't suggest it please.
我正在为移动环境开发,并且我不希望使用jQuery,所以请不要建议它。
You can try catching it with the "beforeunload" event. 您可以尝试通过“ beforeunload”事件来捕获它。
Here's how to use it: 使用方法如下:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.