[英]Action on user leaving the page
在我的HTML代码中,我只想显示用于注册或登录的链接按钮,然后,如果用户对两者都不感兴趣并决定关闭该页面,我想问他是否对查看列表感兴趣。 (通过对话框),然后如果他单击“是”,则转到列表页面。
因此,我决定在开始时使清单链接按钮不可见,并使其在函数myFunction中可见,当页面通过onbeforeunload
关闭或刷新(另一个问题)时应调用该函数。
即使这样行之有效的问题,出现的对话框中的标准行也写着“页面正在要求您确认要离开。输入的数据可能并不安全。” 而不是我在返回后输入的内容。 出于某种原因,我还不允许发布问题,请耐心等待。 这似乎是默认内容。 怎么办 另外,还有更好的方法吗?
这是我的HTML代码:
` <!DOCTYPE HTML>
<html>
<head>
<link rel="stylesheet" type="text/css" href="CSS/a.css">
</head>
<body onbeforeunload="return myFunction()">
<h3>Click the appropriate button</h3>
<div>
<a href="Reg.html"><button style="background-color:red; color:white;">Register</button></a> <br><br>
<a href="Login.html"><button style="background-color:red; color:white;">Login</button></a> <br><br>
<a href="Listings.html"><button class="hidden" id='marketing' style="background-color:green; color:white;">View Listings</button>
</div>
<script>
function myFunction() {
document.getElementById('marketing').style.display='block';
return "Do you want to view listings without registering?";
}
</script>
</body>
</html>`
还有我的CSS代码:
input[type=text], select {
width: 100%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}
input[type=submit] {
width: 100%;
background-color: #4CAF50;
color: white;
padding: 14px 20px;
margin: 8px 0;
border: none;
border-radius: 4px;
cursor: pointer;
}
input[type=submit]:hover {
background-color: #45a049;
}
div {
border-radius: 5px;
background-color: #f2f2f2;
padding: 20px;
}
.hidden{
display:none;
}
[1]: https://i.stack.imgur.com/Q1a9W.png
我忘了写什么,我只是从w3schools那里撕了
享受就好
function myFunction() { var txt; var r = confirm("Press a button!\\nEither OK or Cancel.\\nThe button you pressed will be displayed in the result window."); if (r == true) { window.location.href = "https://stackoverflow.com/" } else { txt = "You pressed Cancel!"; } document.getElementById("demo").innerHTML = txt; }
<h3>Click the appropriate button</h3> <div> <a href="Reg.html"><button style="background-color:red; color:white;">Register</button></a> <br><br> <a href="Login.html"><button style="background-color:red; color:white;">Login</button></a> <br><br> <button id='marketing' onclick="myFunction()" style="background-color:green; color:white;">View Listings</button> </div> <p id="demo"> </p>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.