1.11M Members

detect close browser tab and window.open

 
0
 

i am using ASP.NET
and i am able to detect the close the tab where's the <body onunload="xxx">
but i don't know inside the xxx method how to window.open to another page with new window.

 
0
 

It is not good practice to open another window when another is closed. This irritates your customers/viewers and will typically kill any chance you have at having them repeat visitors.

<body onunload="xxx()">

//funny enough, this is typically the type of site that employs this technique.
function xxx(){
    window.open(URL,name,specs,replace);
}

I haven't tested the code, you'll also need to replace the URL, name... with what you need.

http://www.w3schools.com/jsref/met_win_open.asp

Before you implement this, please think about why you are doing this and if it really is needed as it WILL piss people off and make it so that people won't return to your site.

 
0
 

This should be good for IE, but for Chrome, you'd have to have the user's browser configured to allow pop-ups.

<body onunload="popup()">
<script>
  function popup() {
    popupWin = window.open('http://www.daniweb.com/','Pop-Up','width=640, height=480')
}
</script>

</body>

2a4a7e10344ca4f3c7f5a37fdb676e66

And I agree that you are going to upset your visitors if you open a new window when they close your page.

Attachments
Question Answered as of 9 Months Ago by stbuchok and JorgeM
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article