We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

How do I use javascript to close and then completely refresh the parent window?

Medium Priority
273 Views
Last Modified: 2013-11-19
I've got a problem with what should be a simple javascript refresh!

I have a table where the user can delete a record. When they select delete, they are presented with a popup confirmation window.

When the user confirms, the record should be deleted (this works perfectly), and the popup window should close (this also works perfectly), and finally the parent window should refresh removing the deleted record from the table.

This is the part that does work. I've tried all sorts of combinations of the following code and I've no idea what I'm doing wrong since the parent seems to refresh a little, but there is no change to the page. If I then refresh manually, the table updates and the deleted record disappears.

Ideas what could be the problem?
<form action="" method="post" name="confirm_delete" target="_parent" id="confirm_delete" onclick="self.close(); window.opener.location.reload();" alt="refresh">
        <label>
        <input type="submit" name="Delete" id="Delete" value="Remove Guest" />
        </label>
        <input name="guestid" type="hidden" id="guestid" value="<?php echo $row_guest_select_remove['guestid']; ?>" />
      </form>

Open in new window

Comment
Watch Question

try
parent.opener.location.reload();

btw would it be better if the onclick is triggered on form on submit?

Author

Commented:
Hi quincydude,

No joy unfortunately. It has the same result as before.

I'm also wondering what you meant by your second statement with regards to the onclick trigger.....

Cheers,

BB
//refresh parent window
window.opener.location.reload();
// close self
window.close();

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
The above code shuld be used in the popup page.

Author

Commented:
Hi again there SreejithG!

Could you elaborate on that please? Should it be in a function?

Cheers,

BB
Say you have a button to close the child window. Call the function on click of the button
See the sample below
<HTML>
<HEAD>
<SCRIPT ID=clientEventHandlersJS LANGUAGE=javascript>
<!--
function buttonClose_onclick() 
{
	if(window.opener)
		window.opener.location.reload();
		
	window.close();
}
 
//-->
</SCRIPT>
</HEAD>
<BODY>
<p>
<input type="button" value="Button" id=buttonClose name=buttonClose LANGUAGE=javascript onclick="return buttonClose_onclick()">
</p>
</BODY>
</HTML>

Open in new window

Author

Commented:
I've done exactly what you mentioned and have the same problem still.

Only this time it takes 2 attempts to remove the record. I've no idea what's going on there......

I need to hit the sack as it's 2:25am here and I've got work at 7am!!!!

I'll catch up with this in the morning.

Cheers,

BB
beanbaguk2,

what i meant was not to use onclick but onsubmit

onsubmit="self.close(); window.opener.location.reload();"

as the onclick will be triggered every time the form is being clicked...


please provide full page so that I can get more idea on what u r trying

Author

Commented:
I found an alternative solution. Although what was posted was correct, my circumstances were different and another method was needed. Thanks for the help!
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.