關閉頁面之前 提示使用者(確定跳轉,取消停留)----使用window.onbeforeunload
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:
Java程式碼
- var _isset=0;
- function demo() {
- window.onbeforeunload = function () {
- if (_isset==0) {
- _isset=1; // This will only be seen elsewhere if the user cancels.
-
return
- }
- }
- _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).
--------------------------------------------------------------
雖然如此,但還是有高手給出瞭如下程式碼 ^^
Java程式碼
- <!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>
Java程式碼
- <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.href = "http://www.google.com";
- }
- }
- //]]>
- </script
相關推薦
關閉頁面之前 提示使用者(確定跳轉,取消停留)----使用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
Markdown基礎(內含:錨點使用,使用HTML,新頁面跳轉,目錄生成)
Github樣式顯示參考:點我 之前說過用word寫文章,這次說說Markdown寫文章(推薦) 逆天推薦使用VSCode編寫 裝這個外掛寫作更方便: 內含:錨點使用,使用HTML,新頁面跳轉,目錄生成 啟用方式: H1~H3(#的個數)[部落格園只支援H1~3] # H1 ## H2 ### H3
阻止 android webview 中的連結跳出APP(即跳轉到系統瀏覽器)
//通過此設定,可以讓新頁面的跳轉不用跳出APP, 否則,新的頁面會跳轉到瀏覽器 webView.setWebViewClient(new WebViewClient() { @Override publ
html 中a標籤的問題(無反應,跳轉,呼叫方法)
讓超連結點選後不跳轉,可以用href = "#",但是這個#就會錨點到頁面最上邊 點選連結後不跳轉可以設定成 1.<a href="javascript:void(0);" >javascript:void(0);</a> 2.
Android使用okhttp封裝多檔案批量下載 (帶進度條,取消下載)
在網上搜索了很多關於okhttp封裝的網路框架,唯獨沒找到完美實現了多個檔案批量下載的案例,當前使用的最多的也就是okhttp了,所以,我學習了各位大神的封裝後,自己也試著封裝了一個關於okhttp的網路請求框架,方便專案中的使用。 實現的功能基本如下:
shiro登入驗證(登入跳轉到指定頁面,驗證碼驗證,不登出之前已登入使用者下,再次登入)
web.xml配置 <filter> <filter-name>shiroFilter</filter-name> <filter-class>org.springfr
jQuery使用ajaxSubmit()提交表單(在不希望頁面跳轉的情況下)
ont .ajax 引入 當前 data fun get orm mit 原文:http://www.jb51.net/article/48728.htm ajaxSubmit(obj)方法是jQuery的一個插件jquery.form.js裏面的方法,所以使用此方法需要先
各種頁面定時跳轉(倒計時跳轉)代碼總結
倒數 自動跳轉 str ani import rect ext document color 一、使用setTimeout函數實現定時跳轉(如下代碼要寫在body區域內) <script type="text/javascript"> //3秒鐘之後跳
wamp下DVWA登入頁面無法訪問(或輸入login直接跳轉到setup介面)的解決辦法
老王上網找了好久解決辦法,有說改埠的、有說重啟動的balabala但都沒亂用....真的急瘋了,前兩天在機電樓數字簽名課上中期檢查還好好的,突然輸入login的網址就登不上去了。。。在我一籌莫展抓耳撓腮之時,靈光一現,發現了下面的解決辦法: 大家開啟本地服務(就是下方輸入框
servlet中實現提示登入成功後跳轉到某一頁面
一般J2ee中Jsp+Servlet+JavaBean的servlet中實現的是DoGet和DoPost函式,主要用到DoPost函式打印出某一頁面。 我在servlet中進行了身份驗證,驗證成功後,提示登入成功,之後跳轉到個人主頁等其他頁面,也可以實現提示
小宗的啟示:不同型別的liferay使用者登入到不同頁面(登入跳轉個性化)——liferay5.0.1使用者登入後的跳轉(二)
在liferay5.0.1使用者登入後的跳轉(一) 中,提到新建使用者在去掉首次登入的條例說明,可以自動跳轉到portal.properties設定的固定頁面上。 問題又來了,在實際應用中,不同使用者需要登入到不同頁面進行。而liferay設定的登入跳轉是侷限的,使得不同使用
關閉頁面時提示是否關閉
轉發: 轉發頁面 方法/步驟 jquery離開頁面彈出提示 1jquery離開頁面彈出提示程式碼://繫結beforeunload事件$(window).bind('beforeunload',function(){return '您輸入的內容尚未儲存,確定離開此頁面嗎?'
hao643.com劫持(修改快捷方式跳轉至hao123.com)
手工 mob 彈出 let shell program data 喜歡 lin >癥狀:所有瀏覽器快捷方式,都被加上尾巴,例如IE的:"C:\Program Files\Internet Explorer\iexplore.exe" http://hao643.com
hao643.com劫持(IE和Chrome等被修改快捷方式跳轉到hao123.com)
cnblogs path eat ams app .get style 選型 des 最近下載了某個軟件,安裝後IE和Chrome的Startup Page均被重定向到hao123.com。查看IE和Chrome的配置選型,沒發現問題。後來發現是快捷方式後邊多了一串字符串
減少頁面加載時間(感知或實際加載時間)的方法。
dsm 完全 圖片合成 空格 數量 pos 允許 較高的 trac 版權聲明:本文為博主原創文章,未經博主允許不得轉載。 1. 盡量減少頁面中重復的HTTP請求數量 比較直接的理解就是要減少調用其他頁面、文件的數量。我們在使用css格式控制的時候,經常會采用b
頁面定時刷新或自動跳轉
eth blog www. 方法 mage ase logs res set 采用response對象的setHeader方法可實現頁面定時跳轉或定時自刷新。 1.response.setHeaser("refresh","5");//每隔5秒,頁面自刷新一次 2.resp
【前臺】整個項目實現單頁面跳轉,拋棄iframe
點擊事件 true charset req 做到 value images tro Language 即如下: 【想做到點擊nav側邊欄,僅替換右邊div中的內容,而不是跳轉到新的頁面,這樣的話,其實整個項目中就只有一個完整的頁面,其他的頁面均只寫<body>內
利用cookie,實現刷新頁面跳轉,左側菜單點擊後狀態保持不變。
coo spl 失效 不變 find sco a標簽 左側菜單 cookie 是一個後臺關系系統,後臺是phyton,後臺把左側菜單都是利用a標簽進行跳轉,導致菜單點擊狀態在頁面刷新後失效,用戶體驗不好,被要求改掉。 查了一些資料。利用cookie終於搞定了這個大問題。主要
nginx填坑補充(nginx根據上下文跳轉ip或者域名)
store access allow tro 跳轉 head 不同的 域名 root 今天有一個需求,要根據上下文調到不同的ip或域名地址,使用上下文做域名跳轉的時候,proxy_pass域名後面一定要帶‘/’否則會把nginx的上下文自動帶入,這樣就行。 location
頁面跳轉,A跳到B,B再返回A時自動定位到離開A時的位置
ID 重新 before setview one attr UNC -- ntb <template> <div class="hello" @scroll="scrollLoad" id="myScrollBox"> <h