Redirecting main parent window with JavaScript
-
I'm trying to get some JavaScript so that a number of pop-ups can figure out the parent that spawned them all, close themselves and re-direct the main parent. It works as I want (if it's coming from a pop-up then it'll spawn a new window), but, if I click to show the first pop-up, then close the main parent window, and continue through to the page that executes the below code, it throws up an error:
function findWindow()
{
var currentWnd;
currentWnd = self;while (currentWnd.opener != null && !currentWnd.opener.closed) { var oldWnd = currentWnd; currentWnd = currentWnd.opener; oldWnd.close(); } if (!WindowIsPopup(currentWnd)) { currentWnd.document.location.href='http://www.microsoft.com'; } else { // It's a pop-up, so close it and open a new page altogether. open('http://www.theregister.co.uk'); currentWnd.close(); }
}
Basically, I want to be able to do a check to find out whether I've reached the main parent window, and if it's not open, spawn a new one etc. If anyone has any suggestions, or has done this kind of thing before I'd appreciate their thoughts. Thanks, -- Paul "Put the key of despair into the lock of apathy. Turn the knob of mediocrity slowly and open the gates of despondency - welcome to a day in the average office." - David Brent, from "The Office" MS Messenger: paul@oobaloo.co.uk Download my PGP public key