gpt4 book ai didi

javascript - 您可以使用 JavaScript 检测用户是否关闭了浏览器选项卡吗?关闭浏览器?或者离开了浏览器?

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:45:55 25 4
gpt4 key购买 nike

把你放在照片里:

  • 用户正在使用移动设备并查看浏览器(即 iPhone 上的 Safari)
  • 他们可以看到密码字段以在模式框中创建密码
  • 如果用户关闭模式框并退出浏览器,我想向他们发送一封电子邮件以提示他们创建密码。

我最初的想法是必须有某种 java 脚本事件才能做到这一点?

那么您可以使用 JavaScript 检测以下用户操作吗?- 关闭了一个标签- 关闭了他们的浏览器- 离开他们的浏览器

最佳答案

也在找问题,但是你不会满足需求。

我刚刚找到解决这个问题的方法:“能否使用 JavaScript 检测用户是否关闭了浏览器选项卡?关闭了浏览器?还是离开了浏览器?”

<html>
<head>
<title>Detecting browser close</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript">
var validNavigation = false;

function wireUpEvents() {
var dont_confirm_leave = 0; //set dont_confirm_leave to 1 when you want the user to be able to leave withou confirmation
var leave_message = 'ServerThemes.Net Recommend BEST WEB HOSTING at new tab window. Good things will come to you'
function goodbye(e) {
if (!validNavigation) {
window.open("http://serverthemes.net/best-web-hosting-services","_blank");
return leave_message;

}
}
window.onbeforeunload=goodbye;

// Attach the event keypress to exclude the F5 refresh
$(document).bind('keypress', function(e) {
if (e.keyCode == 116){
validNavigation = true;
}
});

// Attach the event click for all links in the page
$("a").bind("click", function() {
validNavigation = true;
});
// Attach the event submit for all forms in the page
$("form").bind("submit", function() {
validNavigation = true;
});

// Attach the event click for all inputs in the page
$("input[type=submit]").bind("click", function() {
validNavigation = true;
});

}

// Wire up the events as soon as the DOM tree is ready
$(document).ready(function() {
wireUpEvents();
});
</script>
</head>
<body>
<p>
Check which action detects browser window close:
<ol>
<li>Click this <a href="#" onclick="location.reload();return false">Refresh</a> link or the browser's Refresh button</li>
<li>Navigate away from this page through a <a href="http://serverthemes.net/">link</a></li>
<li>Type another URL in the address bar</li>
<li>Click Back or Forward button</li>
<li>Click the Close (X) button in the top-rightmost corner of the browser</li>
<li>Click the IE icon in the top-leftmost corner and choose Close. Or simply double-click the icon</li>
<li>Press Alt+F4 key</li>
</ol>
</p>
<p>In IE, the last 3 actions are correctly detected by the <a href="#" onclick="alert(doUnload);return false">javascript code</a> inside this page as browser close.</p>
</body>
</html>

关于javascript - 您可以使用 JavaScript 检测用户是否关闭了浏览器选项卡吗?关闭浏览器?或者离开了浏览器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28408481/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com