linein designs

02 Mar, 2009

Javascript Close Popup and Refresh or Redirect Parent Window with OnLoad (Solution)

Posted by: john In: javascript| programing

This one about drove me crazy all night trying to think of why this does not work and to be honest I still don’t understand why it doesn’t. But below is a solution to the problem.

The problem was I was trying to close a popup and force the parent page to load a URL using onload.

So within the popup, I saved the form changes to the database and if everything was saved fine it would return to the popup with the code below.

< body onload="window.opener.location = '/directory/?action=confirmation'; window.close();">

But for some reason this would cause IE7 (didn’t check any version below 7 and worked fine in Firefox & Chrome) to just load and load and load but never actually load the page it was sent to. The big blue “e” would just spin. The URL was correct and it wasn’t stuck in some endless loop. But like I said, I’m still not sure what caused it to do that, but below is the solution that seemed to have worked.

Rather than placing the close and redirect in the onload, I simply added them within a script tag and placed it above all the other scripts.


My only guess is that by putting the code in the onload was causing it to not fully run the redirect. Anyway, I hope this helps someone else out there.

Please let me know if you know the reason what caused this error.

Similar Posts:

2 Comments »

Comment by junaid

hi there is have a problem the page is not refresh although i was onload=”window.refresh();” but having same problem not refreshed ,

 
Name (required)
E-mail (required - never shown publicly)
URI
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> in your comment.

Trackback responses to this post



Please Support Our Sponsors

A Payday advance can be a great way to get back on track.

Banner

About

My name is John Veldboom and have been in design and web programing for just over 8 years now. Started off as a hobby in high school but it has developed into a full time job now. I always tell people that if I wasn't doing this at work each day, I would be at home doing it for free. I love it!

Please visit the contact page to drop me a message.