1,105,416 Community Members

detect close browser tab and window.open

Member Avatar
gahhon
Posting Pro
505 posts since Jul 2010
Reputation Points: 13 [?]
Q&As Helped to Solve: 5 [?]
Skill Endorsements: 0 [?]
 
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.

Member Avatar
stbuchok
Posting Shark
957 posts since May 2011
Reputation Points: 123 [?]
Q&As Helped to Solve: 142 [?]
Skill Endorsements: 2 [?]
 
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.

Member Avatar
JorgeM
IT Addict
6,418 posts since Dec 2011
Reputation Points: 581 [?]
Q&As Helped to Solve: 963 [?]
Skill Endorsements: 172 [?]
Moderator
Featured
Sponsor
 
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 6 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