onunload确认是否可以在同一窗口中打开一个新的url?
这是我的第一篇文章,我是一个 JS 新手,所以请原谅我的无知...
这是我的问题,分为两部分:
1.) 在 onunload
处,我想要一个询问用户的警报如果他们想要访问相关的 URL。我正在使用的代码有效,但它会在新窗口中打开 URL,并且即使用户已选择加入,也可能会被弹出窗口阻止程序阻止。有没有办法让它在同一窗口中打开并取消弹出窗口阻止程序?
2.)有没有办法将 onunload 函数从 body 标记中取出并将其放入脚本中?
这是我正在使用的代码:
<script language=javascript>
function confirmit()
{
var closeit= confirm("Before you go would you like to add your press kit to the Search Press Kits database?");
if (closeit == true)
{window.open("http://NEWURLHERE.com");}
else
{window.close();}
}
</script>
</head>
<body onunload="confirmit();">
peace
</body>
提前致谢,
丹
this is my first post and I'm a JS novice, so please forgive my ignorance...
Heres my question, its in two parts:
1.) At onunload
I want an alert that asks the user if they would like to go to a related URL. The code I'm using works, but it open the URL in a new window and this can be blocked by a pop-up blocker even though the user has opted-in. Is there a way to have it open in the same window and negate the pop-up blocker?
2.) is there a way to take the onunload function out of the body tag and put it the script?
Heres the code I'm using:
<script language=javascript>
function confirmit()
{
var closeit= confirm("Before you go would you like to add your press kit to the Search Press Kits database?");
if (closeit == true)
{window.open("http://NEWURLHERE.com");}
else
{window.close();}
}
</script>
</head>
<body onunload="confirmit();">
peace
</body>
Thanks in advance,
Dan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,您可以将其移动到脚本部分:
function contactit() { var closeit=confirm(“在您离开之前,您想将您的新闻资料袋添加到搜索新闻资料袋数据库吗?”); if (closeit == true) {window.open("http://NEWURLHERE.com");} else {window.close();} }
window.onunload = 确认
Yes, you can move it to the script part:
function confirmit() { var closeit= confirm("Before you go would you like to add your press kit to the Search Press Kits database?"); if (closeit == true) {window.open("http://NEWURLHERE.com");} else {window.close();} }
window.onunload = confirmit