![](/img/trans.png)
[英]How to close a custom drop down menu when user clicks somewhere else on the page
[英]In javascript, how to know when the user clicks the page, or close the page?
我的HTML如下所示:
<html>
<head>
...
</head>
<body>
...
<iframe>...<iframe>
<body>
我尝试了几种方法,比如body.onbeforeunload,onclick,onclick,但都不起作用。 非常感谢。
如何知道用户何时点击该页面。
要查找用户是否已单击该页面,可以使用document.addEventListener
document.addEventListener('click',function(event){
alert("clicked");
})
或关闭页面?
可以有两种情况。 您可以关闭选项卡或关闭窗口。 无法检测到关闭窗口。但是可以使用unload和onbeforeunload等事件来检测何时卸载页面。
window.onbeforeunload = function(e) {
alert('Are you sure');
};
从一个页面导航到另一个页面时,这些事件也会触发
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.