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 2 of 2
  1. #1
    PSK
    PSK is offline
    New to the CF scene
    Join Date
    Mar 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Prevent web page being loaded into an iFrame

    Hi all,

    I am facing problem in preventing my web page being loaded into an iFrame. I search in internet and found this solution :

    if (self == top)
    document.documentElement.style.display = 'block';
    else
    top.location = self.location;

    The above java script code is simple redirecting me to the home page of my web site. But I donot want that kind of solution.

    When anybody tried to access my web page through iFrame, it should show an error message like "The content of the web site cannot be loaded into an IFrame". This message should be displayed inside the iFrame.

    For example, if we tried to access "google.com" site in an iframe, the website should not allow the iframe object to load into it, insted it will display an error message along with a provision to open webiste with an external link with it.

    Any help?

    thanks,
    -Sanath

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,619
    Thanks
    0
    Thanked 645 Times in 635 Posts
    Instead of

    top.location = self.location;

    which reloads the page outside of the frame simply use

    self.location = 'noframe.html';

    and put your error message in the noframe.html page.
    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.


  •  

    Posting Permissions

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