[thelist] Prevent a request from redirecting browser....
Ian Anderson
ian at zstudio.co.uk
Tue Mar 29 08:35:13 CST 2005
Burhan Khalid wrote:
> I think what you are looking for are those annoying "leave a site
> popup" type script -- so it can detect if you have gone away from the
> main site or not.
I tried this out, because this is useful for my application too. Result
partially successful, but one big issue remains.
The problem with blocking the window from closing is it works but that
you end up with nothing happening when you try to open links into a
window from email, etc. Which is not nice.
So I tried a variation of this;
*<body onUnload="window.open(self.location, '', '');">
*
Which gives you a new window with the original site and the previous
window shows the newly requested URL.
Which is nearly what I wanted. Unfortunately, you cannot ever close the
application window, as every time you try, it spawns another copy of
itself! So not quite there - made me chuckle though.
So, I gave it a close link that uses a switch to turn off the spawning.
Here's the result
<script language="Javascript">
<!--
sw = true;
function keepopen() {
if (sw) {
window.open(self.location, '', '');
}
}
//-->
</script>
<body onUnload="keepopen()">
<a href="javascript:sw=false; self.close();">close</a>
</body>
It seems to work:
1. you can open email links in 'new' windows
2. if you close the window by accident it reopens
3. if you click "close" it closes
...but...
Big snafu: if you reload the page, it spawns a copy of itself. Over and
over. Very, very nasty.
Can anyone suggest how to get it not to force the new window onreload
and just reload the current window? I have tried a callback function
using window.onreload but couldn't get it to work.
Cheers
Ian
More information about the thelist
mailing list