How to reload the parent frame |
How to reload the parent frame |
RainLover |
Jan 1 2014, 08:49 AM
Post
#1
|
Advanced Member Group: Members Posts: 216 Joined: 16-November 09 Member No.: 10,346 |
Sample parent code:
CODE <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Parent</title> </head> <body> <iframe src="https://dl.dropboxusercontent.com/u/4017788/Labs/child.html" width="200" height="100"></iframe> </body> </html> See it in action: https://googledrive.com/host/0B5jOXzxlxbMhY...Wm8/parent.html Sample child code: CODE <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Child</title> </head> <body> <button onclick="myFunction();">Try it!</button> <script> function myFunction() { parent.location.reload(); } </script> </body> </html> I have tried many methods offered in similar questions to no avail, such as: window.parent.location.reload(); top.location.reload(); etc. What am I missing and what's the right approach? |
pandy |
Jan 1 2014, 10:28 AM
Post
#2
|
🌟Computer says no🌟 Group: WDG Moderators Posts: 20,716 Joined: 9-August 06 Member No.: 6 |
Look at your browsers error console. You should see something like "Permission denied to call method Location.reload". I suppose that is because of the HTTPS.
BTW do you realize that reloading the page in the top frame also means reloading the page in the IFRAME? Or rather the page that was initially in the iframe. |
Christian J |
Jan 1 2014, 10:49 AM
Post
#3
|
. Group: WDG Moderators Posts: 9,630 Joined: 10-August 06 Member No.: 7 |
BTW do you realize that reloading the page in the top frame also means reloading the page in the IFRAME? Or rather the page that was initially in the iframe. If that's an acceptable consequence you might reload the parent with an ordinary link with TARGET="_parent" in the framed page (not sure if there's a difference in caching behavior). If it's not an acceptable consequence, you might use a frameset with two frames instead. (And of course frames are problematic, but you probably already know that...) |
RainLover |
Jan 1 2014, 10:54 AM
Post
#4
|
Advanced Member Group: Members Posts: 216 Joined: 16-November 09 Member No.: 10,346 |
|
pandy |
Jan 1 2014, 12:49 PM
Post
#5
|
🌟Computer says no🌟 Group: WDG Moderators Posts: 20,716 Joined: 9-August 06 Member No.: 6 |
The URL you posted doesn't look dynamic. Do you mean host that file at different places and they all use the same framed page?
In that case, from the top of my head, this should work. In the function. CODE window.parent.location = window.parent.location; |
RainLover |
Jan 1 2014, 12:54 PM
Post
#6
|
Advanced Member Group: Members Posts: 216 Joined: 16-November 09 Member No.: 10,346 |
The URL you posted doesn't look dynamic. Do you mean host that file at different places and they all use the same framed page? Actually I'm working on a Google gadget that should be used on different pages and by different users. Then the parent frame URL depends on the gadget user's website. |
pandy |
Jan 1 2014, 12:55 PM
Post
#7
|
🌟Computer says no🌟 Group: WDG Moderators Posts: 20,716 Joined: 9-August 06 Member No.: 6 |
I edited my post above while you posted. Would that work for you?
|
RainLover |
Jan 1 2014, 12:59 PM
Post
#8
|
Advanced Member Group: Members Posts: 216 Joined: 16-November 09 Member No.: 10,346 |
|
pandy |
Jan 1 2014, 01:06 PM
Post
#9
|
🌟Computer says no🌟 Group: WDG Moderators Posts: 20,716 Joined: 9-August 06 Member No.: 6 |
Of course it doesn't. Stupid me. We already knew JavaScript reload doesn't work. Sorry.
OK, but what about the basic problem, that you host the pages at those servers that use HTTPS. Can't you host them somewhere else? Or maybe it's possible not to use HTTPS. Don't know, use neither service. |
pandy |
Jan 1 2014, 01:11 PM
Post
#10
|
🌟Computer says no🌟 Group: WDG Moderators Posts: 20,716 Joined: 9-August 06 Member No.: 6 |
Wait, maybe it isn't because of HTTPS. Could it be a cross-domain thing? JavaScript isn't allowed to modify pages cross domains, but I would have thought a simple reload would work, but maybe it doesn't.
The more I think about it, the more likely it feels that that's the cause. |
RainLover |
Jan 1 2014, 01:11 PM
Post
#11
|
Advanced Member Group: Members Posts: 216 Joined: 16-November 09 Member No.: 10,346 |
|
pandy |
Jan 1 2014, 05:10 PM
Post
#12
|
🌟Computer says no🌟 Group: WDG Moderators Posts: 20,716 Joined: 9-August 06 Member No.: 6 |
Yeah, I realized that shortly after I wrote the above. I can't think how to get around it.
|
Christian J |
Jan 1 2014, 06:50 PM
Post
#13
|
. Group: WDG Moderators Posts: 9,630 Joined: 10-August 06 Member No.: 7 |
Don't know if this will circumvent the cross-domain block. Let the site owner put the parent page's URL (urlencoded) in the iframe SRC's querystring:
CODE <iframe src="http://gadget.com/?url=http%3A%2F%2Fwww.foo.com%2F"> (if this is too difficult for the site owners, maybe you could create a script that generates the IFRAME code for them). Then a script in the framed page would request the URL in the querystring. |
pandy |
Jan 1 2014, 08:34 PM
Post
#14
|
🌟Computer says no🌟 Group: WDG Moderators Posts: 20,716 Joined: 9-August 06 Member No.: 6 |
I don't think that would work either because JS in the framed page can't redirect the top frame.
|
RainLover |
Jan 2 2014, 07:03 AM
Post
#15
|
Advanced Member Group: Members Posts: 216 Joined: 16-November 09 Member No.: 10,346 |
Thanks Christian & pandy! I finally came up with a simple solution:
Child: CODE <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Child</title> </head> <body> <button onclick="myFunction();">Try it!</button> <script> function myFunction() { window.parent.location = document.referrer; } </script> </body> </html> |
Christian J |
Jan 2 2014, 09:38 AM
Post
#16
|
. Group: WDG Moderators Posts: 9,630 Joined: 10-August 06 Member No.: 7 |
|
Christian J |
Jan 2 2014, 09:42 AM
Post
#17
|
. Group: WDG Moderators Posts: 9,630 Joined: 10-August 06 Member No.: 7 |
window.parent.location = document.referrer; That might work too. (If you want to be careful, check that the browser does send the referrer header (since it's optional). Also check that the browser allows iframes, and that the framed page isn't loaded outside the parent page.) |
pandy |
Jan 2 2014, 11:37 AM
Post
#18
|
🌟Computer says no🌟 Group: WDG Moderators Posts: 20,716 Joined: 9-August 06 Member No.: 6 |
But window.location didn't work before. This stuff drives me nuts. Is JS really supposed to be able to change the URL of the top frame from a different domain? Then why didn't my suggestion work?
|
Christian J |
Jan 2 2014, 03:08 PM
Post
#19
|
. Group: WDG Moderators Posts: 9,630 Joined: 10-August 06 Member No.: 7 |
But window.location didn't work before. Oops, forgot about that (though apparently the OP managed to get around the cross-browser restriction anyway). QUOTE Is JS really supposed to be able to change the URL of the top frame from a different domain? Maybe the restrictions are not implemented in a thorough way. Also that ability seems necessary for "break out of frames" scripts to work. QUOTE Then why didn't my suggestion work? Maybe it doesn't reload (even from cache) if the URL is the same. How about adding a querystring to the new one to make it appear different? |
RainLover |
Jan 3 2014, 04:02 AM
Post
#20
|
Advanced Member Group: Members Posts: 216 Joined: 16-November 09 Member No.: 10,346 |
But window.location didn't work before. This stuff drives me nuts. Is JS really supposed to be able to change the URL of the top frame from a different domain? Then why didn't my suggestion work? This article might clarify the point: http://www.nczonline.net/blog/2013/04/16/g...iframes-parent/ |
Lo-Fi Version | Time is now: 29th March 2024 - 09:05 AM |