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.

Member Avatar

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(){

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


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.

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()">
  function popup() {
    popupWin = window.open('http://www.daniweb.com/','Pop-Up','width=640, height=480')



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