/    Sign up×
Community /Pin to ProfileBookmark

close popup, parent change content

Can anyone give me insight for code that simply changes the parent window url once the popup window is closed?

[url]www.thisisplaid.com[/url]

much appreciated,
leo

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@Phil_KarrasJul 06.2004 — Something like this might do the trick:
<i>
</i>&lt;head&gt;
&lt;script language="JavaScript" type="text/javascript"&gt; &lt;!--

var win1 = window.open(...); // This opens the popup to check for.

CheckIt();
function CheckIt() {
if(win1.closed) {
document.location.href = NewURL;
}
else {
setTimeout("Checkit();", 200);
}
}

// --&gt; &lt;/script&gt;
&lt;/head&gt;

Where win1 is the var that holds the pointer to the pop-up window, as in: var win1 = window.open(...); Just make sure that win1 is a global var or this won't work.

Actually there's no such method as "closed" see below for my try-catch method in the parent window that will work.
Copy linkTweet thisAlerts:
@russellJul 06.2004 — In the popup window
<i>
</i>function closeMe() {
window.opener.location.href="newURL";
self.close();
}
Copy linkTweet thisAlerts:
@Phil_KarrasJul 06.2004 — My former posting won't really work. russell's code will work if you can change the code in the pop-up window.

If you can't change the code in the pop-up you can use this code in the parent window:
<i>
</i>&lt;html&gt;
&lt;head&gt;

&lt;script language="JavaScript" type="text/javascript"&gt; &lt;!--

// ################################################
// ##### Test functions go here #####
// ################################################

var win1 = 0;
var tmp = 0;
var ID = 0;

// -----------------------------------------------------
// Clears the recursive timeout and opens a new page in
// this window.
//
// inputs: get the global ID value &amp; clears the timer
// outputs: none
// actions: changes the URL of this page
// returns: none
// -----------------------------------------------------
function GotIt() {
clearTimeout(ID);
document.location.href = "index.htm";
}

// -----------------------------------------------------
// Continually checks for an open pop-up
//
// inputs: none
// outputs: none
// actions: catches the error when the popup is closed
// and gives control to GotIt() function.
// returns: none
// -----------------------------------------------------
function CheckIt() {
ID = setTimeout("CheckIt();", 500); // check ever 1/2 second

<i> </i> try {
<i> </i> tmp = win1.document.innerHTML;
<i> </i> }
<i> </i> catch (e) {
<i> </i> GotIt();
<i> </i> }
}

// -----------------------------------------------------
// Opens a pop-up window
//
// inputs: none
// outputs: none
// actions: calls CheckIt() function
// returns: none
// -----------------------------------------------------
function LoadMe() {
win1 = window.open("help292.htm", "test"); // This opens the popup to check for.
CheckIt();
}


// ################################################
// ##### End of: test functions #####
// ################################################

// --&gt; &lt;/script&gt;
&lt;/head&gt;

&lt;body onLoad='LoadMe();'&gt;
.
.
.
&lt;/body&gt;
&lt;/html&gt;

This does work, I've tested it in Mozilla and there are no errors other than the one caught.

I tried using onerror but it always caused another error, so either I was doing something wrong, or hadn't thought it out correctly.
×

Success!

Help @leandro spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.27,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...