View Full Version : Prevent web page being loaded into an iFrame

03-28-2012, 10:35 AM
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';
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?


03-28-2012, 07:27 PM
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.