English 中文(简体)
Clicking browser Back button autoactive activities
原标题:Clicking browser back button auto-activates event listener

我有一个奇怪的问题,只有一些浏览器才会出现,我无法找到任何解决办法。

Here s the objective:

Make a simple page with a hyperlink. When the hyperlink is clicked, a box immediately appears telling the user to wait while the next page is being fetched from the network. If the visitor doesn t have javascript, then the box won t appear and the next page would attempt to load. The non-javascript version is fine, but the javascript version gives problems.

在Palenti,第123.0版和Mook Moore,第10版中,如果用户试图装上下页,就会在浏览器上点击背子,盒子就自动出现(不应发生)。

在Seamonkey, 2.53.18.2 一切工作都是正确的。

这里使用的PHP代码I能够复制这一问题。 问题也可以不使用购买力平价部分加以复制。

<?php
//this code fragment simulates when the resource was last updated
//so then I load the resource once and generate status 304 when user clicks the back button

date_default_timezone_set( America/Toronto );
$uset=strtotime("2024-04-13 6:20PM"); 
$lmod=gmdate("D, d M Y H:i:s T",$uset);
$ifms=$_SERVER["HTTP_IF_MODIFIED_SINCE"];
header( Last-Modified:  .$lmod,true);
if (isset($ifms{1}) && $ifms===$lmod){
header( HTTP/1.1 304 NM ,true);exit();
}
?>
<!DOCTYPE HTML>
<html>
<head>
<style>
#wbox{
display:none;
border-radius:1em;
border:1px solid black;
background:#FFFFAA;
color:#000000
}
</style>
</head>
<body>
<h1>Content loader</h1>
<a ID="clickee" href="something.htm">Click here</a>
<div ID="wbox">
<h2>Loading contents...</h2>
</div>
<script>
function showbox(){
document.getElementById( wbox ).style.display="block";
}
document.getElementById( clickee ).addEventListener("click",showbox);
</script>
</body>
</html>

能否是,新的浏览器正在遇到ug,或者在我的代码上,我可以做些什么来防止在用户通过点击“背”纽顿而返回网页时自动出现“装载内容”箱。

Oh,如果用户在点击背纽顿后点击复机/重载纽顿,问题就消失了,但其不便点击2顿,而只点击1个。

如上所述,我在多个浏览器中测试了我的代码。 只有在离开网页时,而不是在使用浏览器的“背”纽吨重新进入网页时,才会出现“装载内容”箱。

问题回答

似乎,当回击纽顿时,这页并不引发负荷。

Here is the simplest trick to achieve what you need. Replace the content of the body with this:

<h1>Content loader</h1>
<a onclick="showbox(true)" href="something.htm">Click here</a>
<div ID="wbox">
<h2>Loading contents...</h2>
</div>
<script>
function showbox(show){
    document.getElementById( wbox ).style.display = show ? "block" : "none";
}

document.addEventListener( visibilitychange , () => {
    if (document.visibilityState ===  hidden ) {
        showbox(false);
    }
});
</script>

请注意,我修改你的代码,将显示器直接从标签上称作显示器,我还添加真实或虚假的字句(how或隐藏)。

我补充说,如果你已经离开这个网页(这意味着该页不再见),那么宣传面就会隐藏。





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签