最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

關于捕獲用戶何時點擊window.onbeforeunload的取消事件

 更新時間:2011年03月06日 17:15:47   作者:  
關于捕獲用戶何時點擊window.onbeforeunload的取消事件的代碼,需要的朋友可以參考下。
Detecting When The User Has Clicked Cancel
One of the things you may want to do is to be notified when the user clicks cancel, aborting a page unload. Unfortunately there's no way to be immediately notified. The best you can do is to set a unique global variable in your "onbeforeunload" event and then look to see if that variable has been set in other functions. There is no way to get an immediate notification that the user has aborted a page unload.
The example code I used above to do an example of an "onbeforeunload" dialog is as follows:
復制代碼 代碼如下:

var _isset=0;

function demo() {
window.onbeforeunload = function () {
if (_isset==0) {
_isset=1; // This will only be seen elsewhere if the user cancels.
return "This is a demonstration, you won't leave the page whichever option you select.";
}
}
_isset=0;
window.location.reload();
return false;
}

This code defines a global variabled named _isset, and then initializes it to zero. In our "onbeforeunload" event the variable is checked and if it's set to one, no unload dialog box will appear. The only way _isset could ever be one is if the user previously aborted a page unload.

But as you can see this method won't help you if you need to be immediately notified that that the user has finished dealing with the confirmation box. You can detect when it appears on the screen but there's no way to know when the user has finished interacting with it if the user clicked cancel (if the user clicked OK, then of course the unload event will have been tripped).
--------------------------------------------------------------
雖然如此,但還是有高手給出了如下代碼 ^^
復制代碼 代碼如下:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<title>onbeforeunload test</title>
<script type="text/javascript"><!--
window.onbeforeunload = function() {
// in Firefox and Netscape 7.2+ the setTimeout or setInterval do not wait
// to be executed until after the user clicks one of the buttons in the
// confirm()-like box.

//setTimeout("alert('hi from setTimeout()');",500);
// setTimeout() and setInterval() aren't called when ok is clicked in
// IE5-6/Win, but is called in IE7 when the time is short, but not when
// it's longer, like 500 (a half second).
window.unloadTimer = setInterval(
"alert('hi from setInterval()');clearInterval(window.unloadTimer);",500);
window.onunload = function() {clearInterval(window.unloadTimer);}
return 'onbeforeunload testing';
}
// -->
</script>
</head>
<body>
<h1>onbeforeunload test</h1>
</body>
</html>

復制代碼 代碼如下:

<script type="text/javascript">
//<![CDATA[
var
is_asked = false;

window.onbeforeunload =
function (ev) {
var e = ev || window.event;
window.focus();
if (!is_asked){
is_asked = true;
var showstr = "CUSTOM_MESSAGE";
if (e) { //for ie and firefox
e.returnValue = showstr;
}
return showstr; //for safari and chrome
}
};

window.onfocus =
function (ev){
if (is_asked){
window.location.;
}
}

//]]>
</script

相關文章

  • JavaScript空數(shù)組的every()方法實踐

    JavaScript空數(shù)組的every()方法實踐

    every()方法用于檢測數(shù)組中的所有元素是否都滿足指定條件, 本文主要介紹了JavaScript空數(shù)組的every()方法實踐,具有一定的參考價值,感興趣的可以了解一下
    2024-03-03
  • JS target與currentTarget區(qū)別說明

    JS target與currentTarget區(qū)別說明

    target在事件流的目標階段;currentTarget在事件流的捕獲,目標及冒泡階段。只有當事件流處在目標階段的時候,兩個的指向才是一樣的,而當處于捕獲和冒泡階段的時候,target指向被單擊的對象而currentTarget指向當前事件活動的對象(一般為父級)。
    2011-08-08
  • js實現(xiàn)根據(jù)身份證號自動生成出生日期

    js實現(xiàn)根據(jù)身份證號自動生成出生日期

    這篇文章主要介紹了js實現(xiàn)根據(jù)身份證號自動生成出生日期,需要的朋友可以參考下
    2015-12-12
  • 詳解?Map?和?WeakMap?區(qū)別以及使用場景

    詳解?Map?和?WeakMap?區(qū)別以及使用場景

    這篇文章主要介紹了詳解?Map?和?WeakMap?區(qū)別以及使用場景,Map本質(zhì)上是一個鍵值對的集合,WeakMap?只能將對象作為鍵名,下面來一起倆姐更多詳細內(nèi)容吧,希望這一篇文章能讓你對?Map?有更好的理解,或者能夠幫你理解?Map?和?WeakMap
    2022-01-01
  • HTML+CSS+JavaScript實現(xiàn)可拖拽模態(tài)框

    HTML+CSS+JavaScript實現(xiàn)可拖拽模態(tài)框

    這篇文章主要為大家詳細介紹了HTML+CSS+JavaScript實現(xiàn)可拖拽模態(tài)框,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-07-07
  • JS去除數(shù)組重復值的五種不同方法

    JS去除數(shù)組重復值的五種不同方法

    去除數(shù)組重復值的方法有很多,本文整理了四種不同方式,在此與大家分享下,希望對大家有所幫助
    2013-09-09
  • javascript實現(xiàn)百度地圖鼠標滑動事件顯示、隱藏

    javascript實現(xiàn)百度地圖鼠標滑動事件顯示、隱藏

    這篇文章主要介紹了javascript實現(xiàn)百度地圖鼠標滑動事件顯示、隱藏的思路和方法,十分的實用,這里推薦給小伙伴們,有需要的朋友可以參考下。
    2015-04-04
  • 說明你的Javascript技術很爛的五個原因

    說明你的Javascript技術很爛的五個原因

    Javascript在互聯(lián)網(wǎng)上名聲很臭,但你又很難再找到一個像它這樣如此動態(tài)、如此被廣泛使用、如此根植于我們的生活中的另外一種語言。
    2011-04-04
  • Layer組件多個iframe彈出層打開與關閉及參數(shù)傳遞的方法

    Layer組件多個iframe彈出層打開與關閉及參數(shù)傳遞的方法

    今天小編就為大家分享一篇Layer組件多個iframe彈出層打開與關閉及參數(shù)傳遞的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-09-09
  • 微信小程序webview中監(jiān)聽返回按鈕實現(xiàn)步驟

    微信小程序webview中監(jiān)聽返回按鈕實現(xiàn)步驟

    在微信小程序中webview返回鍵是一個非常實用的功能,它允許用戶在嵌入的網(wǎng)頁中返回到上一個頁面,這篇文章主要給大家介紹了微信小程序webview中監(jiān)聽返回按鈕的實現(xiàn)步驟,需要的朋友可以參考下
    2024-08-08

最新評論

庐江县| 武山县| 清河县| 德庆县| 喜德县| 会同县| 柘荣县| 南丹县| 玉山县| 富裕县| 吉木萨尔县| 团风县| 永福县| 通海县| 仁化县| 商都县| 金昌市| 彭阳县| 工布江达县| 武邑县| 昭平县| 嵩明县| 山丹县| 班玛县| 汝阳县| 卢龙县| 镶黄旗| 鞍山市| 红安县| 瑞丽市| 晋州市| 梓潼县| 扎兰屯市| 全椒县| 宁安市| 福海县| 搜索| 潮安县| 东城区| 乌什县| 建始县|