Re: [請益] 請教一個控制開新網頁的問題

看板Web_Design作者 (rrr0832)時間8年前 (2017/05/05 20:19), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串2/2 (看更多)
像這種就要設定一個變數來判斷 預設變數為false 但唯獨按下按鈕時變數才會變成true 在onbeforeunload時再來判斷那個變數是否為true或者false就好了 原始碼如下: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script> var f=false; window.onbeforeunload=function(){ if(!f) window.open('http://www.google.com/','new_window'); }; </script> </head> <body> <button onclick="f=true;window.location='" rel="nofollow">http://tw.yahoo.com/'">按我不會跳出視 窗</button><br><a href="" rel="nofollow">http://www.facebook.com/">按我會跳出視窗</a> </body> </html> ※ 引述《pttzoo (別放棄希望 ^^)》之銘言: : 請問一下 : 目前工作上有個需求 : 是當使用者離開網頁(或關閉網頁) : 跳出新開一個問卷調查的網頁 : 但當使用者按button超連結離開 : 就不要跳出網頁 : 請問該用什麼方式來控制 : 謝謝 : 附上目前寫的內容 : ================================================================== : <html> : <head> : <title></title> : </head> : <script> : function close_page() : { : window.open('http://www.google.com' , 'new_window'); //離開或關閉就開新網頁 : } : </script> : <body onbeforeunload ="close_page()"> : <button onclick="location.href='" rel="nofollow">http://www.yahoo.com'">按此離開不跳出網頁 : </button> : </body> : </html> -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 101.139.172.23 ※ 文章網址: https://www.ptt.cc/bbs/Web_Design/M.1493986771.A.F4D.html

05/08 15:08, , 1F
感謝,已解決
05/08 15:08, 1F
文章代碼(AID): #1P36tJzD (Web_Design)
文章代碼(AID): #1P36tJzD (Web_Design)