onunload确认是否可以在同一窗口中打开一个新的url?

发布于 2024-09-01 12:23:20 字数 680 浏览 2 评论 0原文

这是我的第一篇文章,我是一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深居我梦 2024-09-08 12:23:21
  • 如果有办法绕过弹出窗口阻止程序,那么它将是一个糟糕的弹出窗口阻止程序。
  • 据我所知你需要一个弹出窗口,因为当执行 onUnload 时,原始窗口可能已经关闭。
  • 是的,您可以将其移动到脚本部分:

    function contactit() { var closeit=confirm(“在您离开之前,您想将您的新闻资料袋添加到搜索新闻资料袋数据库吗?”); if (closeit == true) {window.open("http://NEWURLHERE.com");} else {window.close();} }
    window.onunload = 确认

  • If there would be a way to bypass the pop-up blocker it would be a bad pop-up blocker.
  • As far as I know you need a popup, because when onUnload is executed, the original window might be already closed.
  • 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文