/    Sign up×
Community /Pin to ProfileBookmark

Refresh main page from iframe

Hello everybody !!!
I’m making my first attempts at php… The point is to make a skinnable website, which will remember the choice of the user…
I found a great tutorial on how to do that, but I still have ONE problem…
I’m using an iframe… So, when the new skin is selected, it works for the current page in the iframe, but you have to reload the page ( using ctrl + R ) to get the new skin on the main page…
I was wondering if there was anything I could do to simulate a ctrl+ R when the user clicks the skin he wants…
I’m sure it must be something very basic, but as I’m only beginning in php, I have no idea how to do it, as it’s not the actual page I want to reload, but the parent page… The current page can be reloaded, I don’t care, but I would like to have a general refresh of all the website…
Of course, I could redirect the page, or reload the main page, but then, I couldn’t have the skin selection page in the iframe…
I don’t know if you can follow me, I’m not really clear, sorry…
Thanks for all suggestions !
Ness

to post a comment
PHP

18 Comments(s)

Copy linkTweet thisAlerts:
@phpnoviceMar 04.2005 — There are only two "automatic" type choices:

#1 A link in the IFRAME is coded with [b]target="_parent"[/b] (or some such) to reload the parent document.

#2 JavaScript is used in the IFRAME document as follows (or some such):

self.parent.location.reload(true);
Copy linkTweet thisAlerts:
@Ness_du_FratauthorMar 04.2005 — Great !!!

I used the second one, to refresh the main page... The problem is, I get the iframe src stated in the main page...

I mean, the iframe default source is a page called edito.htm.

What I would like to have, is the page with the version change thing, called version.htm.

When we do a reload with ctrl + r, it refreshes both the main page and the iframe page, but it doesn't change the current page in the iframe, and that's exactly what I want.

Do you have any idea how I could do that ? Or if it's not possible to have the main page refresh without changing the page in the iframe, is it possible to pass a variable from the iframe to the main page, so as to change the iframe source in the main page ?

I hope I'm not being too complex..
Copy linkTweet thisAlerts:
@phpnoviceMar 04.2005 — [i]Originally posted by Ness_du_Frat [/i]

[B]The problem is, I get the iframe src stated in the main page...



...snip...



Do you have any idea how I could do that ? Or if it's not possible to have the main page refresh without changing the page in the iframe, is it possible to pass a variable from the iframe to the main page, so as to change the iframe source in the main page ?[/B]
[/QUOTE]

Not with this:
<i>
</i>self.parent.location.reload(true);

but you could use this:
<i>
</i>self.parent.location.href = self.parent.location.href + '?iframe=' + self.location.href;

then, your parent document would need JavaScript to extract this information (perhaps, at [b]onload[/b] time) and override the IFRAME SRC attribute. Such as this:
<i>
</i>ary = self.location.search.substr(1).split("&amp;");
ary[0] = ary[0].split("=");
if (ary[0][0]=="iframe") {
self.frames["iframeName"].location.href = ary[0][1];
}
Copy linkTweet thisAlerts:
@Ness_du_FratauthorMar 04.2005 — this seems really gret, but I can't understand the javascript part...

I'm lost... ?

I don't understand where you put the page name in the script..

I mean, on load, I have lets say welcome.htm, and if I want version.htm, where should I put version.htm ???

I'm a desperate case, I know...

I'm going to try this script...
Copy linkTweet thisAlerts:
@phpnoviceMar 04.2005 — [i]Originally posted by Ness_du_Frat [/i]

[B]I mean, on load, I have lets say welcome.htm, and if I want version.htm, where should I put version.htm ???[/B][/QUOTE]

This part of the code is where that would go:
<i>
</i>self.parent.location.href = self.parent.location.href + '?iframe=' + self.location.href;

as follows -- for example:
<i>
</i>self.parent.location.href = self.parent.location.href + '?iframe=version.htm';

However, I supplied the original code to purposefully load the same document that is currently in the IFRAME. I presume this would be "version.htm" at that time. Yes?
Copy linkTweet thisAlerts:
@Ness_du_FratauthorMar 04.2005 — so, let's sum it all up...

In my main page, the one including the iframe, I put this scary script, the long one with the ary thingy. You say I should put it onLoad. Do I need to make a function with it and to call the function onLoad ?

Then, in my version.htm page, I put the self.parent.location blabla thing... Should I put it directly on the link, like an

<a onClick="self.parent.blablabla">Link</a> or somewhere else in the page ?

About the main page, now... Will the script affect the fact than in ALL other cases, the edito.htm page is supposed to be loaded in the iframe, înstead of the version.htm ?

I feel really lost...

Could you explain the scary script to me ? I think if I understand it better, I might be able to come out with something less crappy than what I've written....

Thanks a lot for taking time with me...
Copy linkTweet thisAlerts:
@phpnoviceMar 05.2005 — Yes, the "scary" script, as you call it, would be made into a function that is executed at [b]onload[/b] time. "ary" is an abbreviation for "array" -- since it is not advisable to spell words exactly as they should be without knowing exactly what you are doing (because of possible conflicts with keywords in JavaScript, the DOM, etc.).

Also, yes, you can code that redirect in a link in the IFRAME document -- though you don't have to. There are a number of ways to utilize it depending upon your the esthetics of your exact need. ;-)

Lastly, the sole purpose of that "scary" script is to detect if a non-default document should be loaded into the IFRAME. If the "iframe" keyword is not found attached to the URL of the main page, then whatever you have coded for the IFRAME SRC will remain displayed in the IFRAME. Otherwise, the IFRAME document will be replaced at load time by whatever is specified as the value for the "iframe" keyword in the URL.
Copy linkTweet thisAlerts:
@Ness_du_FratauthorMar 05.2005 — OK !!!!

I think I get it now... I was mostly wondering about this "ary" thing.. I thought it was array, but as I don't know everything, I wasn't sure... It could well be something I'd never heard of...

So, of course, I replace ary by array, right ? ?
Copy linkTweet thisAlerts:
@SpectreReturnsMar 05.2005 — Please don't post two of the same thread. It makes me confuzed about what forum I'm in (as well as could be considered spam).
Copy linkTweet thisAlerts:
@Ness_du_FratauthorMar 05.2005 — sorry, but I posted one on the javascript forum to know how to do it in JS, and on in the php forum to get a php solution. It's not spam, it's just trying different languages to achieve something. I don't consider it spamming...
Copy linkTweet thisAlerts:
@SpectreReturnsMar 05.2005 — Sorry, but I don't understand what you're trying to do, but if it's what I think, you can't do it in PHP.
Copy linkTweet thisAlerts:
@Ness_du_FratauthorMar 05.2005 — phpnovice, I've tried your script, and somehow, the "scary" script keeps my menu from working ?

if you want to have a look at what I'm talking about :

[URL=http://psychomoa.free.fr/accueiltest.php]Les Enfants de l'Ô[/URL]

There is nothing on the website, yet..

The "Version Violette" and "Version Blanche" are the links changing the version, but what I wanted to achieve was to have these links in the version page, located under Site, in the menu Divers...

Maybe I did something wrong....

I created a function called frame(), with the scary script, where ary was replaced by Array, and this was called on load.

In the links, I had an onClick event, which was the self.parent.location stuff...

I finally took it all out, because it's no way I can make the menu open if the scary script is activated... ?

Any idea why it doesn't work and how I could have it work ?
Copy linkTweet thisAlerts:
@SpectreReturnsMar 05.2005 — It works for me...
Copy linkTweet thisAlerts:
@Ness_du_FratauthorMar 05.2005 — yeah, but do you have a menu working on javascript ?

Because I'm pretty sure it would work for me too, but my menu doesn't work if I put this script in the main page...

According to you, it's not possible in php ? I don't know a lot about php, but as the version things were done in php, I thought I might as well use php for the rest...

*sigh*

For the moment, the solution I tried didn't work for me... I feel desperate...

Sorry for bothering you all with that..
Copy linkTweet thisAlerts:
@phpnoviceMar 05.2005 — [i]Originally posted by Ness_du_Frat [/i]

[B]So, of course, I replace ary by array, right ? ? [/B][/QUOTE]

No! I tried to make the point that you should NOT spell words correctly as your variables names unless you know EXACTLY what you are doing -- even some abbreviations can get you into trouble in some languages. Creating a variable name with a number on the end of it (e.g., [b]array2[/b]) is about the safest method. Now, if you want to name it [b]tempArray[/b], then you can certainly do so. :p
Copy linkTweet thisAlerts:
@Ness_du_FratauthorMar 05.2005 — yeah, I figured that out just after writing the post...

Actually, it creates a conflict with my javascript menu...

The menu doesn't open anymore... ?
Copy linkTweet thisAlerts:
@phpnoviceMar 05.2005 — So, did you get it worked out so that both can be in the same page?
Copy linkTweet thisAlerts:
@Ness_du_FratauthorMar 05.2005 — no, not yet...

I think the real problem is the style switcher I^'m using. I got it from a tutorial, and the good point is, I could understand how it was done...

Pittimann offered to help me, and so far, I think he's up to something really good...

If you want, I can post the code here when he comes up with it, so that you see the final solution !

But thanks a lot for having helped me... thanks to you, I could make it work on the main page, where it didn't work before !!!
×

Success!

Help @Ness_du_Frat spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...