I'm a total js newbie but I have the feeling that this can be done easily. I have a pop-up iframe. What I want to do is automatically refresh its parent window. No problem there and I was able to do it with this simple code: <body onload="parent.location.reload(2)"> Code (markup): Now my dilemma is that when it refreshes its redirecting back the user to the homepage. I don't wanna do that. I want the current URL/destination to be preserved. I was able to achieve this via the onclick event with <a href...>. But how do you do I do it in my case with the onload event? I want it to be done automatically. I would really appreciate anyone shedding some light over me. Thank you.
The trick here is ajax. Anytime you want to refresh part of a page but not all of it, ajax is the way to go. You will need to figure out which part of the page you want to refresh (sounds like everything except the frame) and update all of that content. Developing the actual code for that might be a little time consuming, but it should be do-able.
Refreshing the whole page is what I want here and thus getting rid of the pop-up iframe. I just have to make sure that the current URL destination is being preserved. You are right going the ajax way is too much work. I also looked into this method where I consider only reloading certain divs on the parent to achieve what I want but I rather use the onclick event than go for ajax. With this code I am able to do what I want except for the automatic part. <a href="#" onClick="parent.location.reload(1)">Close</a> Code (markup): I am able to automate it though using the body onLoad event and as I said this is redirecting me back to the homepage. How do you implement <a href="...."> in the onLoad body? (If that will solve my problem.)
Ok, maybe I'm not understanding what it is you want. What do you mean by "automatic"? Do you mean when the page loads, or a certain portion loads? Please explain what action is occuring when you want the page to reload.
Automatic means that instead of the user to click on the 'close' button to close and refresh the page, the page reloads on its own so yes when the page loads as in the whole thing. I have a popup iframe that needs to be closed when reaching the last page consequently reloading the parent. Hope thats clear enough. P.S: Don't ask why I resorted in using iframe instead of jquery/ajax for the popup window. It's a long story.
Note that the popup occurs everywhere on the site through a link. That is why I need to preserve its destination.
Correct me if I'm wrong, but wouldn't reloading the page when it is done loading the pop-up make it so that the user doesn't have time to read the pop-up? Did you want to wait a couple seconds and then reload?
The user already had all the time reading the popup before reaching the page where I want to implement this. Here's the logic. User clicks the link - popup - serve page 1 - click next - serve page 2 - click next - serve page 3 - fill up some stuff - hit the submit button - boom! popup closed. There's a confirmation page after hitting the submit button so this is where my code goes. I'm using this page to trigger the popup to close and refresh parent. As I said I'm able to achieve this with onLoad event (onload="parent.location.reload(1)). I just want the destination to be preserved.
Ahhhh, gotcha. So what you're going to want to do is make use of the PHP global variable $_SERVER['HTTP_REFERER']. When you open you're popup, you should get this variable on the first page because that is when it will be set to the value you want. Now that you have that variable, the best way to pass it between pages is through a get variable. Let's say for example the user clicked the link to pop-up the frame. You can now set the variable $return = $_SERVER['HTTP_REFERER']; PHP: Now, when the user clicks the link to the next page, make sure the url has looks something like this: http://domainname.com/filename.php?return=$return Code (markup): You can then get the original page variable on page 2 of the pop-up with $_GET['return']. You can use this technique to pass the original url from page to page until the end. At that point you can simply redirect the user to that url. ..:: Edit ::.. Just occured to me that if you are using sessions in your site then it would be easier to simply set a session variable instead of passing the value from page to page.
Thank you for your input. However I'm looking for a quick js solution and my cms needs register_globals to be be turned on and using $_SERVER['HTTP_REFERER'] variable would pose a security issue. I would rather use the onClick event than to go through this. As with the sessions my site only implements it for logged in user. This popup is only for anonymous/visitors. Thank you.
I suppose what you are looking for is: <html> <head> <script type="text/JavaScript"> <!-- function timedRefresh(timeoutPeriod) { setTimeout("location.reload(true);",timeoutPeriod); } // --> </script> </head> <body onload="JavaScript:timedRefresh(10000);"> <iframe src="web_page" width="page_width" height="page_height"></iframe> </html> Code (markup):
I don't think he wants a timed refresh. Anyway, I don't know how else you would get the page you want to be sent back to. I suppose you could pass it as a post variable or set it in the session, but I'm not sure how it would be done with javascript. Maybe just call something like this: <script type="text/javascript">window.location.reload(true);</script> Code (markup): That might reload the background frame if the frame is a javascript or jquery pop-up, but if it is a seperate browser frame then you may have to pass a variable of some kind.