SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    Non-Member
    Join Date
    Apr 2003
    Location
    Denver, CO
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    keeping an iframe from loading outside its source

    Hi-

    I'm somewhat new to Javascript -- I'm more of a back end programmer -- and I've been asked to tackle something that I'm not quite sure how to do. Basically, I need some code that prevents the contents of an iframe from loading outside their source. Namely, the page has its main text content in an iframe so it can be scrolled through while keeping fixed size layouts. That iframe points to a file, content.html, that I want to keep the user from loading directly in the browser. I'd like it so, if they do go to content.html directly, it will just boot them back to the main index.

    Is this possible? Thank you.

  2. #2
    SitePoint Enthusiast hutchysk8er's Avatar
    Join Date
    Apr 2003
    Location
    Scotland
    Posts
    61
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    insert this into the head of the content.html file
    Code:
    <script language="javascript" type="text/javascript">
    if (window.name!='xxx' && window.name!='booker_'
    		 && !((self.innerHeight == 0) && (self.innerWidth == 0)))
    		top.location.replace('index.html?content.html~xxx');
    </script>
    and replace "xxx" with the iframe name. this should work.
    Hutchy

  3. #3
    SitePoint Member
    Join Date
    Aug 2003
    Location
    Netherlands
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Something like this in your iframe:
    Code:
    <script type="text/javascript">
    var yd='http://yourdomain.com/index.html';
    if (parent.location!=yd)parent.location=yd;
    <script>
    Regards, Martijn


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
  •