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 for stbuchok

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.