Re: [请益] 请教一个控制开新网页的问题

楼主: rrr0832 (rrr0832)   2017-05-05 20:19:28
像这种就要设定一个变量来判断
默认变量为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='http://tw.yahoo.com/'">按我不会跳出视
窗</button><br><a href="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='http://www.yahoo.com'">按此离开不跳出网页
: </button>
: </body>
: </html>
作者: pttzoo (别放弃希望 ^^)   2017-05-08 15:08:00
感谢,已解决

Links booklink

Contact Us: admin [ a t ] ucptt.com