View Full Version : force orphan into iframe on index.html
quag2000@hotmai
04-15-2005, 11:06 PM
Hi,
I'm sure this has been asked a million times, but I can't find an example that I can make work.
Note: I am not familiar with variables and javascript so I need it explained as "cut & paste" as possible :)
I am trying to force my orphaned content pages to reload back into their iframe on my index.html page. EG if a search engine indexes a content page and some one clicks it in their results, it will then load and refresh itself into the main EXISTING frame in index.html
<SCRIPT LANGUAGE="JavaScript">
<!--
if (top == self) self.location.href = 'http://www.staticfarm.com/index.html' target='iframe';
// -->
</SCRIPT>
Please try the following example
parent page
<HTML>
<HEAD>
<TITLE>Document Title</TITLE>
<script type="text/javascript">
<!--
loc="page1.htm" // default page loading into the iframe
var str = location.search;
if(str != ""){
loc=str.substring(1, str.length)
}
function load_frame(){
document.body.style.overflow="hidden"
document.getElementById('iframe1').src=loc
}
// add onload="load_frame()" to the opening BODY tag
// -->
</script>
</HEAD>
<BODY onload="load_frame()">
<h1>Parent Page</h1>
<iframe id="iframe1" src="page1.htm"></iframe>
</BODY>
</HTML>
iframe pages
<HTML>
<HEAD>
<TITLE>Document Title</TITLE>
<script type="text/javascript">
<!--
if (self == top){
var url = self.location;
self.location = "parent.htm?" + url;
}
// -->
</script>
</HEAD>
<BODY>
<h1>Page 1</h1>
</BODY>
</HTML>
quag2000@hotmai
04-17-2005, 06:09 AM
Thanks heaps for your help.
I tried (repeatedly) to get that example to work, but to no avail.
the 2 pages i am fiddling with are www.staticfarm.com/index.html
and www.staticfarm.com/products/bias.html
It seems that I am unable to figure out how to pass the URL from the original page into the iframe. The iframe is called further down the page.
In HTML i would just href it with a target="iframe" in the link, but as this is being provided by a variable read from the URL i dont know how to call it up in the <iframe src=VARIABLE HERE> kind of context.
Many thanks for your help.
Cheers
:(
In your index page you need a semicolon after the call to load_frame() in the body tag
onload="load_frame() ; MM_preloadImages('images/
In the iframe pages you need this
<script type="text/javascript">
<!--
if (self == top){
var url = self.location;
self.location = "index.htm?" + url;
}
// -->
</script>
Change index.htm to the name of the parent page if this is not correct.
On a side note is better not to use the word iframe as the name and id of your iframe, use something like my_frame or even iframe1
quag2000@hotmai
04-17-2005, 11:47 AM
Mr J.
Thou art truly a scholar and a legend.
It seems that the changing of my iframe id / name and the addition of the semicolon has done the job.
Thankyou so much!
Cheers
:thumbsup:
quag2000@hotmai
04-17-2005, 12:34 PM
That is working a treat for me.
A couple of small questions though.
1) can you mask the redirected URL? I'm getting the result of http://www.staticfarm.com/index.html?http://www.staticfarm.com/products/bias.html when the bias.html page reloads into its iframe.
No big deal really, but it would look a bit slicker.
2) in dreamweaver, when I insert
<SCRIPT LANGUAGE="JavaScript" type="text/javascript">
<!--
if*(self*==*top){
var*url*=*self.location;
self.location*=*"http://www.staticfarm.com/index.html?"*+*url;
}
// -->
</script>*
I am not sure if there is a cure for your 1st question but if I do come across one I will let you know.
As for your second question, is part of the question missing?
glenngv
04-18-2005, 12:52 PM
Double-posted! (http://www.codingforums.com/showthread.php?t=57060)
quag2000@hotmai
04-18-2005, 03:08 PM
I am not sure if there is a cure for your 1st question but if I do come across one I will let you know.
As for your second question, is part of the question missing?
ahh yes.
It dumped everything after the script tag closed.
The question was:
After the script above, dreamweaver claims my BODY tag is no longer valid. It says that it does not belong inside the tag it is in etc.
If i delete the script all is good again. Is dreamweaver just being fussy?
it is the same pages links as initally above if you wanted to see how I've done it. I thought I'd not closed a tag or script, but cant see any probs.
Cheers.
As I have never used DreamWeaver I am not sure but it could be being fussy.
You could try moving the call to load_frame to the end of the onload and see if that makes a difference.
<BODY onload="MM_preloadImages('images/Static-mouseover_06.jpg','images/Static-mouseover_07.jpg','images/Static-mouseover_08.jpg', 'images/Static-mouseover_09.jpg','images/Static-mouseover_10.jpg') ; load_frame()" bgcolor="#f3f3f3" LEFTMARGIN=0 TOPMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0>
The above should be all one line.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.