在我的应用程序我必须在关闭标签或浏览器时强行注销用户。我有注销功能,我想在用户关闭标签/浏览器时调用它。我试过这块代码,但它不适合我
<script type="text/javascript">
$(function () {
$(window).bind("beforeunload", function () {
fnLogOut();
})
});
function fnLogOut() { alert('browser closing'); }
</script>
任何帮助?
答案 0 :(得分:0)
window.onbeforeunload = function (event) {
var message = 'Important: Please click on \'Save\' button to leave this page.';
if (typeof event == 'undefined') {
event = window.event;
}
if (event) {
event.returnValue = message;
}
return message;
};
$(function () {
$("a").not('#lnkLogOut').click(function () {
window.onbeforeunload = null;
});
$(".btn").click(function () {
window.onbeforeunload = null;
});
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a href="#" target="_blank"> ----BY </a>
<a href="#" class="btn" target="_blank"> STY------- </a>
&#13;