Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Aug 2006
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to Check if page is not in a frame?

    How would I check if a page is not inside a frame and then redirect it somewhere else if it isn't? Thanks.

    thewird
    Last edited by thewird; 11-04-2006 at 11:22 PM.

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,616
    Thanks
    0
    Thanked 645 Times in 635 Posts
    if (top.location == self.location) location.href = 'newpage.htm';
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #3
    New Coder
    Join Date
    Aug 2006
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Oh thanks, thats exactly what I wanted (still didn't test it but it looks right).

    Now does anyone know what the variables would be for getting the domain only from the URL? I want to see if the frame's domain matches the top-frame's domain. Thanks.

    thewird

  • #4
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    you may check also for the host or hostname property of the location object.
    See also:
    http://www.devguru.com/Technologies/.../location.html
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #5
    New Coder
    Join Date
    Aug 2006
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Kor View Post
    you may check also for the host or hostname property of the location object.
    See also:
    http://www.devguru.com/Technologies/.../location.html
    Would hostname or host be more suited to compare the domain?

    thewird

  • #6
    New Coder
    Join Date
    Aug 2006
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok, I think I got it but it doesn't seem to be working, this is my code...

    The code is placed inside the frame but it doesn't direct for some reason.
    Code:
    if (top.location.host != self.location.host) top.location.href = "http://"+location.host;
    thewird


  •  

    Posting Permissions

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