The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

2 Pages V  1 2 >  
Reply to this topicStart new topic
> How to reload the parent frame
RainLover
post 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?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post 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.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Jan 1 2014, 10:49 AM
Post #3


.
********

Group: WDG Moderators
Posts: 9,630
Joined: 10-August 06
Member No.: 7



QUOTE(pandy @ Jan 1 2014, 04:28 PM) *

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...)
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
RainLover
post Jan 1 2014, 10:54 AM
Post #4


Advanced Member
****

Group: Members
Posts: 216
Joined: 16-November 09
Member No.: 10,346



QUOTE(Christian J @ Jan 1 2014, 10:49 AM) *

If that's an acceptable consequence you might reload the parent with an ordinary link with TARGET="_parent" in the framed page


How can I do that when the parent frame URL is dynamic -- it's not fixed?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post 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;
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
RainLover
post Jan 1 2014, 12:54 PM
Post #6


Advanced Member
****

Group: Members
Posts: 216
Joined: 16-November 09
Member No.: 10,346



QUOTE(pandy @ Jan 1 2014, 12:49 PM) *

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.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post 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?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
RainLover
post Jan 1 2014, 12:59 PM
Post #8


Advanced Member
****

Group: Members
Posts: 216
Joined: 16-November 09
Member No.: 10,346



QUOTE(pandy @ Jan 1 2014, 12:55 PM) *

I edited my post above while you posted. Would that work for you?


Thanks for the snippet, but it doesn't work.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post 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.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post 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.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
RainLover
post Jan 1 2014, 01:11 PM
Post #11


Advanced Member
****

Group: Members
Posts: 216
Joined: 16-November 09
Member No.: 10,346



QUOTE(pandy @ Jan 1 2014, 01:06 PM) *

OK, but what about the basic problem, that you host the pages at those servers that use HTTPS.


HTTPS isn't the problem here. It's a cross-domain issue but I cannot host both frames on the same domain.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post 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.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post 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.

User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post 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. sad.gif
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
RainLover
post 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>
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Jan 2 2014, 09:38 AM
Post #16


.
********

Group: WDG Moderators
Posts: 9,630
Joined: 10-August 06
Member No.: 7



QUOTE(pandy @ Jan 2 2014, 02:34 AM) *

I don't think that would work either because JS in the framed page can't redirect the top frame. sad.gif

Can't you use something like top.location.href then? unsure.gif

Or you could let JS create a link with a TARGET="_parent" for the user to click on.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Jan 2 2014, 09:42 AM
Post #17


.
********

Group: WDG Moderators
Posts: 9,630
Joined: 10-August 06
Member No.: 7



QUOTE(RainLover @ Jan 2 2014, 01:03 PM) *

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.)
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post 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?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Jan 2 2014, 03:08 PM
Post #19


.
********

Group: WDG Moderators
Posts: 9,630
Joined: 10-August 06
Member No.: 7



QUOTE(pandy @ Jan 2 2014, 05:37 PM) *

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. unsure.gif 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?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
RainLover
post Jan 3 2014, 04:02 AM
Post #20


Advanced Member
****

Group: Members
Posts: 216
Joined: 16-November 09
Member No.: 10,346



QUOTE(pandy @ Jan 2 2014, 11:37 AM) *

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/
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

2 Pages V  1 2 >
Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 29th March 2024 - 09:05 AM