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 5 of 5
  1. #1
    Regular Coder Coastal Web's Avatar
    Join Date
    Oct 2004
    Posts
    225
    Thanks
    12
    Thanked 3 Times in 3 Posts

    JS frame breaker hlp..

    Hello everyone I've got a quick question that l was hoping one of your Javascript Vets would be able to help me with...

    My site uses the following javascript to "break" out of frames when a site links to mine using a framed page (which happens quite often):

    <!--snip of code...
    if (window != top) {
    top.location.href = location.href;
    }
    //end of snip--->

    However the situation has come up that l *want* to allow one specific domain to be able to link to my site, and keep the frames intact.

    By using something like this:
    <!--snip of code...
    if ((window != top) && && (topURL.indexOf("www.someDomain.com") > 0)) {
    top.location.href = location.href;
    }
    //end of snip--->

    The question;
    How would l set the variable of topURL to be that of the site that's linking to me with the frame?

    Any help would be greatly appreciated.
    Samantha gram

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    top.location.href

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #3
    New Coder
    Join Date
    Dec 2005
    Posts
    88
    Thanks
    0
    Thanked 0 Times in 0 Posts
    if ((window != top)&&(document.referrer!="http://www.allowedsite.com"))
    {
    top.location.href = location.href;
    }

  • #4
    Regular Coder Coastal Web's Avatar
    Join Date
    Oct 2004
    Posts
    225
    Thanks
    12
    Thanked 3 Times in 3 Posts
    Thank you konithomimo;

    <!--snip
    str = document.referrer;
    if ((window != top) && (str.indexOf("allowedDomain.com") < 0)){
    top.location.href = location.href;
    }
    //end snip-->

    does the trick

    Samantha Gram

  • #5
    New Coder
    Join Date
    Dec 2005
    Posts
    88
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You are very welcome.


  •  

    Posting Permissions

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