Open new broswer window on close

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Open new broswer window on close

Post by JayBird »

Hi,

I am trying to open a new browser window when someone closes to main window of my site. This window logs the user out if they haven't click the LogOut button.

First off i thought this was easy and used the onUnload function to achieve this until i realised that onUnload means the current document that you are viewing on the site. This means that a new window is opened evertime you click a link within the site.

Unfortunately, there is no onClose function in Javascript.

So, how can i open a new window, only when i close the current window.

I have seen it done on online banking sites. The HSBC site does it, but i can't access that at the moment to "borrow" their code. :lol:

Any ideas?

Mark
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

From the HSBC site, because although I'm useless with JS I do have access to the source of this site :lol:

Code: Select all

<script language="Javascript">
<!--
var doit=true;
function logoff(url) &#123;
    if(doit) &#123;
	    var win;
	    win=window.open(url,win,"scrollbars=no, width=350, height=215, left=80, top=70");
	    win.focus();
	&#125;
&#125;
//-->

</script>
and

Code: Select all

<frameset border="0" frameborder="0" framespacing="0" rows="100%,0\*" onunload="logoff('https://www.ebank.hsbc.co.uk/servlet/com.hsbc.ib.app.pib.cp.Logoff?success=/main/logoff.jsp&error=/main/gensorry.jsp');" >
	<frame frameborder="0" framespacing="0" marginheight="0" marginwidth="0" scrolling="no" name="master" noresize src='https://www.ebank.hsbc.co.uk/welcomebackindex.jsp' />
</frameset>
Mac
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

ah, i see, they use frames to get around the problem of the new window opening even when you navigate to a new page within the site.

Clever.... :)

Mark
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Are there any other ways to achieve this without using frames?

Mark
Post Reply