PDA

View Full Version : click link - open site in _blank - close page..



keentolearn
05-26-2006, 11:13 AM
Hi all

i have searched for help on this, i hope i havent missed the answer - here goes..

is it possible to have a link that when you click on opens the link in a new browser window and closes the orginal window

i know:

<a href="../page-name.html" target="_blank">link</a>

will open the url in a blank window - but how to close the first window at the same time?

thanks for any help
as ever
keen to learn..

Flic
05-26-2006, 11:15 AM
onClick="javascript:window.close"

keentolearn
05-26-2006, 11:20 AM
hi

thanks for the help

so how do i combine the js to do both open the link in a new browser window and close the first browser?

thanks again
keen to learn..

Flic
05-26-2006, 01:38 PM
<a href="../page-name.html" target="_blank" onClick="javascript:window.close();">link</a>

Bill Posters
05-26-2006, 03:06 PM
<a href="../page-name.html" target="_blank" onClick="javascript:window.close();">link</a>

Firstly, that's unlikely to work because most browsers disallow* the use of js to close windows which weren't created using js.
(* I recall seeing someone post a js method to 'trick' into allowing it FF, but I can't recall it. There is also a method to trick IE6 into allowing it, but I think that vulnerability was closed down in either an IE6 point upgrade or possibly the SP2 XP upgrade.
You might find it by searching here or Googling around.)

Secondly…
onClick="javascript:window.…

The 'on' events are already capable of handling js directly, so you really don't need to invoke the javascript protocol as well.

i.e.

<a href="../page-name.html" target="_blank" onClick="window.close();">link</a>

…though, like I said, it won't work without the tricks; and even then, it's still unlikely to work reliably x-browser.
Personally, unless this is for an intranet situation, I wouldn't even attempt to close the main window.
You risk upsetting a user's browser session and they may thank you for it by leaving your site never to return.
I've never heard of someone leaving a site never to return because they didn't close the main window.

Open a new window if you feel that you must, but try to avoid messing about with the user's main window.

keentolearn
05-26-2006, 03:18 PM
hi flic / bill

thanks for the posts - its a strange request i know and asked for a pretty unique reason.

i will have to think of another way to make this work.

thanks for the time.

as ever
keen to learn..