Results 1 to 5 of 5

Thread: auto-loading frames page

  1. #1
    Join Date
    Aug 2008
    Posts
    16
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default auto-loading frames page

    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.

  2. #2
    Join Date
    Jul 2008
    Posts
    128
    Thanks
    0
    Thanked 17 Times in 16 Posts

    Default

    Quote Originally Posted by philnolan3d View Post

    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.
    Code:
    (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" );

  3. #3
    Join Date
    Aug 2008
    Posts
    16
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default

    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

  4. #4
    Join Date
    Jul 2008
    Posts
    128
    Thanks
    0
    Thanked 17 Times in 16 Posts

    Default

    Quote Originally Posted by philnolan3d View Post
    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
    I just assumed you'd know about <script> tags.

    Code:
    <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>

  5. #5
    Join Date
    Aug 2008
    Posts
    16
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default

    Nope my knowledge of web coding pretty much ended in 1997 with basic HTML. 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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •