Re: [請益] 請教一個控制開新網頁的問題
像這種就要設定一個變數來判斷
預設變數為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
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):
Web_Design 近期熱門文章
PTT數位生活區 即時熱門文章