开发者

Is it posible to use "confirmit" to open new url in the same window?

I'm using a the confirmit java script function to redirect to a new url with a positive response. It doesn't do exactly what I want - and maybe I can't have exactly what I want.

Here's what it does - onunload, with a positive response it opens the new url in a new window, which can be blocked by a pop-up blocker without the user even knowing, giving the impression that nothing happened. When it does open the new URL it opens in a new window making the desktop crowded. Its just not a great solution.

What I want it to do - onunload I'd like it to 开发者_C百科open the new url in the same window and have it not be classified as a "pop-up" to be blocked. I tried switching to onbeforeunload.... nuthin.

Is there a simple solution?

here's my current code:

<script language=javascript>
function confirmit() 
{ 
var closeit= confirm("My message"); 
if (closeit == true) 
{window.open("http://MyDestinationURL");} 
else 
{window.close();} } window.onunload = confirmit  
</script> 


Instead of opening a new window you can set the location of the current window:

<script type="text/javascript">

function confirmit()  { 
  if (window.confirm("My message")) {
    window.location.href = 'http://MyDestinationURL';
  } else {
    window.close();
  }
}

window.onunload = confirmit;

</script>

I am not sure if you actually want the else case where it tries to close the current window. If you just want to stay on the current page on a negative response, remove the else part.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜