PDA

View Full Version : auto-loading frames page



philnolan3d
08-27-2008, 09:21 AM
I finally finished and uploaded my website redesign:
http://www.philnolan3d.com

I've already received a huge number of hits and no major complaints so I'm happy. However while watching my stats I can see that a number of hits are coming from Google and people are hitting my "child frames" instead of the main parent page. Probably because the child pages have the same file names as my old site.

So what I'd like to do is have the child page automatically load the main site if someone hits it by accident, like through Google or another search engine. I'm sure I've seen scripts for doing that in the past. The problem would be that it's essentially loading itself along with the main frame, so it would create an infinite loop if my logic works correctly.

Anyone have a suggestion on what to do? I figured the Javascripts forum was the best place to ask.

clueful
08-27-2008, 04:45 PM
So what I'd like to do is have the child page automatically load the main site if someone hits it by accident, like through Google or another search engine. Try this in the <head> section. As well as restoring an orphaned document, it will break out of any foreign frameset. Just change 'mysite.com' to your top domain.

(function(myURL)
{
try
{
if(top==self || top.document.domain != self.document.domain)
top.location.href = myURL;
}
catch(e){ top.location.href = myURL; }

})( "http://mysite.com" );

philnolan3d
08-27-2008, 05:24 PM
Thanks, but all that's doing is placing the code at the top of the page. Unless I misunderstood. I changed just the mysite.com to http://www.philnolan3d.com but that didn't do it so I changed all of the myURL parts to my address as well, still no difference.

Here's the page I added it to:
http://www.philnolan3d.com/resume.html

clueful
08-27-2008, 07:01 PM
Thanks, but all that's doing is placing the code at the top of the page. Unless I misunderstood. I changed just the mysite.com to http://www.philnolan3d.com but that didn't do it so I changed all of the myURL parts to my address as well, still no difference.

Here's the page I added it to:
http://www.philnolan3d.com/resume.htmlI just assumed you'd know about <script> tags.


<script type='text/javascript'>

(function(myURL)
{
try
{
if(top==self || top.document.domain != self.document.domain)
top.location.href = myURL;
}
catch(e){ top.location.href = myURL; }

})( "http://mysite.com" );

</script>

philnolan3d
08-27-2008, 07:12 PM
Nope my knowledge of web coding pretty much ended in 1997 with basic HTML. :p Thanks though, it seems to work perfectly. Now I just hope if people click a "resume" link in Google they're smart enough to find the Resume link on the page. :)