Forum Moderators: open
I need to force child pages into their parents iframe when they are direct linked.
I have been using
<script type="text/javascript">
if(top.location == self.location)
{
top.location.href = 'main.html'+'?addr='+this.location.href;
}
</script>
to force load the parent page but, the iframe will only load its original source page (intro.html) and not the child that was externally linked to in the first place, although the url becomes http://www.example.com/main.html?addr=http://www.example.com/contact.html. do i need to parse the url with something?
I have tried using
<script type="text/javascript">
var loc_var=this.location.href;
if(loc_var.indexOf('?addr='!=-1){
var loc_arr=loc_var.split('?addr=');
document.getElementById('mainframe').src=loc_arr;)
}
</script>
and
<script type="text/javascript">
if(top.location == self.location)
{
top.location.href = 'main.html'+'?addr='+this.location.href;
}
</script>
in the child pages with no luck. The iframe is:
<iframe id="mainframe" src="intro.html" scrolling="auto" marginwidth="1" marginheight="1" width="100%" height="750" frameborder="1" vspace="1" hspace="1"></iframe>
Can anyone give me a script to make contact.html load in the iframe on main.html instead of intro.html when contact.html is directly linked
[edited by: tedster at 7:06 am (utc) on Sep. 25, 2008]
[edit reason] switch to example.com - it can never be owned [/edit]
FORCE MANY PAGES INTO FRAMES [webmasterworld.com]
with one simple script
That approach can be adapted for an iframe rather easily. Yes, it does make for an ugly url, and potentially a duplicate content issue for the search engines. So you need noindex for it -- but it works.
The key is that you need a second copy of main.html - one where the iframe src is modified with javascript so it can use the url that was passed as a query string variable.
Thats exactly what i've been trying to do.
I now have a duplicate of main.html called master.html, the only difference being the iframe being written with
<script language="JavaScript" type="text/javascript">
origURL = parent.document.URL
contentURL = origURL.substring(origURL.indexOf('?')+1, origURL.length)
document.write('<iframe src=\"' + contentURL + '\" id="mainframe" scrolling="hidden" marginwidth="1" marginheight="1" width="100%" height="750" frameborder="1" vspace="1" hspace="1"><\iframe>')
</script>
The redirection on the child pages:
<script type="text/javascript">
passpage = document.URL
if (top.location == self.location)
top.location.href="master.html?" + passpage
</script>
It also means i dont need to add a new version of nav links or duplicate every page, thought i was going to need ones without the redirect at all to load into the original main.html without forcing master.html but this has sorted that problem out in one hit.
Plus when the site is accessed through the root directory, the frame isnt sitting there idle with no child loaded like the other lesser solution i had been toying with.
Very tasty,
Thanks.
[edited by: Roosterteeth at 9:37 pm (utc) on Sep. 25, 2008]