Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Close popup, and reload parent?

Status
Not open for further replies.

youradds

Programmer
Jun 27, 2001
817
GB
Hi,

I'm trying to close a popup window when a link is clicked, and reload the parent window. However, this doesn't seem to work:


Code:
<script>
 function reload_and_close() {
		window.opener.location.reload(); 
         self.close();
 }
</script>
		<p>[ <a href="#" onclick="reload_and_close();">close window</a> ]<p>

Its fine in FF, but IE is being crappy (as always ;)), and refuses to play ball.

Any suggestions?

TIA

Andy
 
Have you tried doing it from the parent instead, something like:

Code:
var winHandle = window.open(...);

...

function closeAndRefresh() {
   winHandle.close();
   location.reload();
}

...

// This goes in the popup
<a href="#" onclick="window.opener.closeAndRefresh();">close window</a>

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Hi,

Nah, would you mind explaining a bit more how this is done? I've never used this approach =)

TIA

Andy
 
It's the opposite of what you were trying to do.

You were trying to refresh the parent from the popup, and then close the popup from itself.

My code calls a function in the parent from the popup, which closes the popup and then refreshes itself.

Did it not work for you? I admit to not testing it, but thought it should work.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Hi,

Thanks - I'm still a bit confused as to how I would launch the new window though? At the moment, I'm just doing it with:

<a href="#" onclick="window.open(args)">link to click</a>

...how would I do that with your code?

TIA, and I appreciate your time :)

Cheers

Andy
 
That was the first line of my code. The only difference is that you're not storing a handle to the opened window. If you merge my code with yours, it should work:

Code:
<a href="#" onclick="winHandle = window.open(args);">link to click</a>

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Hi,

Sorry, got sidetracked :( Just tried it - and doesn't seem to work :/

On the parent code - I have this JS in the <head>:

Code:
<script>
function closeAndRefresh() {
   winHandle.close();
   location.reload();
}
</script>

Then, further down that page - I have:

Code:
[ <a href="#" onclick="winHandle = window.open('[URL unfurl="true"]http://domain.org/v.f?do=client_admin;action=validate_account_do;client_id=11','validateaccount',[/URL] 'width=400,height=300,toolbar=no,location=no,directories=no,status=no, menubar=no,scrollbars=no,copyhistory=no,resizable=no')">validate account</a> ] <br />
 [ <a href="#" onclick="winHandle = window.open('[URL unfurl="true"]http://domain.org/v.f?do=client_admin;action=reject_account_do;client_id=11','validateaccount',[/URL] 'width=400,height=300,toolbar=no,location=no,directories=no,status=no, menubar=no,scrollbars=no,copyhistory=no,resizable=no')">refuse account</a> ]


Then, on the popup window, when we wanna close it - we have:

Code:
<p>[ <a href="#" onclick="window.opener.closeAndRefresh();">close window</a> ]<p>

One thing I forgot to mention (can't see it being the problem - but I could be wrong)

When the popup opens, it has a form - which they fill out - and press a "submit" button. Once thats done, it then show the "close" link (and needs to reload the parent page.

Could that be whats causing the problem?

IE is soooo rubbish at reporting errors back in terms of JS code :(

TIA!

Andy
 
With or without a form submission in the popup, the code you've shown above works perfectly for me in both IE 6 and Fx 3. The popup is closed, and the parent refreshed.

Perhaps you have a JS error somewhere that's stopping the script from running?

Have you tried looking in Firefox's error console (Tools -> Error console) to check?

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
MMm, in IE it gives me:

Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; WOW64; Trident/4.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.30729; InfoPath.2; OfficeLiveConnector.1.3; OfficeLivePatch.0.0; .NET CLR 3.0.30729)
Timestamp: Tue, 3 Nov 2009 07:06:23 UTC

Message: 'winHandle' is undefined
Line: 668
Char: 2
Code: 0
URI:

:/

TIA

Andy
 
I'm all out of ideas, other than strongly suggesting you try another browser, like Firefox, to rule out your IE 8 configuration (it will also give you the chance to check the error console to see if the same error appears, or perhaps if you get more data about the error).

Failing that, I can only suggest posting a URL to the site, as I know the code is sound.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Hi,

The weird thing, is it works perfectly in FF and Chrome - just not IE 8 :/

Unfortunatly I can't post the URL, as its a private site - and all password protected :(

Cheers

Andy
 
Hi,

Very odd - just tried doing it as a basic .html page, and that works fine :/ I wonder why its refusing to work in the script :/

Cheers

Andy
 
Ok not ideal, but with the script I'm using, we have tags is_mozilla - so I've now got:

Code:
		<%if is_mozilla%>
			<p>[ <a href="#" onclick="window.opener.closeAndRefresh();">close window</a> ]<p>
		<%else%>
			<p>[ <a href="#" onclick="window.close();">close window</a> ]<p>
		<%endif%>

Obviously that doesn't reload the parent window in IE - but at least the popup closes =)

Cheers

Andy
 
OK - I just tried on IE 8 as well and it works perfectly for me there, too, so I'm guessing you've got some odd setting in your IE8.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
P.S. With your "is_mozilla" code - surely you'd be better off saying "is_ie", as that way you don't penalise all the users of Opera, Chrome, Safari, etc?

Another thing - have you tried running the code on another version of IE, or IE 8 on another PC?

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Hi,

Yeah, to be honest - its not a major thing. This is just an admin interface, where we can validate the users who signup. We only use FF and IE (although I don't use IE, as its a load of rubbish ;)) ... so doing it like I have should work just fine :)

Unfortunatly I don't have another PC with IE on to test with, so couldn't check if it was just my configuration :)

Cheers

Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top