onunload确认是否可能在同一个窗口中打开一个新的URL? [英] Is it possible for onunload confirm to open a new url in the same window?

查看:175
本文介绍了onunload确认是否可能在同一个窗口中打开一个新的URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的第一篇文章,我是一个JS新手,所以请原谅我的无知...



我的问题,它分为两部分: p>

1。)在 onunload 我想要一个提醒,询问用户是否想去相关的URL。我正在使用的代码,但是它会在新窗口中打开该URL,即使用户已选择加入,也可以由弹出窗口阻止程序阻止它。有没有办法在同一个窗口中打开它,否定弹出窗口阻止程序?



2。)有没有办法把onunload功能从身份标签,并把它的脚本?



我正在使用的代码:

 code>< script language = javascript> 
函数confirmit()
{
var closeit = confirm(你要去之前你想添加新闻包到搜索新闻组数据库?);
if(closeit == true)
{window.open(http://NEWURLHERE.com);}

else
{window.close( );}
}
< / script>

< / head>

< body onunload =confirmit();>
peace
< / body>

提前感谢



/ p>

解决方案


  • 如果有办法绕过弹出窗口阻止程序,那将是一个坏的弹出窗口阻止程序

  • 据我所知,您需要一个弹出窗口,因为当执行onUnload时,原始窗口可能已经关闭。

  • 是的,您可以将其移动到脚本部分:




    函数confirmit(){var closeit = confirm(在你走之前,你想添加新闻包到搜索新闻组数据库?); if(closeit == true){window.open(http://NEWURLHERE.com);} else {window.close();}}
    window.onunload = confirmit


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

解决方案

  • 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

这篇关于onunload确认是否可能在同一个窗口中打开一个新的URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆