This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes close browser, open new window Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "close browser, open new window" Watch "close browser, open new window" New topic
Author

close browser, open new window

Marcel de Jong
Ranch Hand

Joined: May 27, 2002
Posts: 54
Hello,
is it possible to open a new window when the user closes the browser or when they type in a new URL in the address bar?
Regards,
Marcel
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
on exit pop ups are a pain to code since there is no way to catch it in an easy manner.
onunload will work on links and everything else like back button, etc. The easiest way is frames, have the onload on an visibnle frame and when that is closded it will open it up, but then you loose the functionability of the site.
Onunload pop ups will drive people away from your site
Marcel de Jong
Ranch Hand

Joined: May 27, 2002
Posts: 54
Hi,
first of all "Happy New Year" to every one. ;-)
I've tried using unload, and it is working. However, it does it every time I unload the page. It also fires when I leave the page via a link. Thats what I don't want. I only want to popup to show when the user exits the page via:
- a new URL in the addresbar
- exiting the browser
Any ideas?
Marcel
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
The only way you can do it is with frames.......
Marcel de Jong
Ranch Hand

Joined: May 27, 2002
Posts: 54
So it is possible?
can you tell me how to do it?

Thanks,
Marcel
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
frame of zero height
the frame never changes.,.
have this code in the source
<script>
function OpenIt(){
PeopleWillHateYou=window.open('TheyWillNotComeBack.htm');
}
window.onunload=OpenIt;
</script>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: close browser, open new window
 
Similar Threads
javascript closing windows
hide the browser address and tool bar?
Sessions in JSP page
Can we still open a window using window.open if popups are blocked.
New Browser Window