Iframe stands for inline frame. An Iframe is a floating frame that can be inserted anywhere within a web page.
A concern for webmasters about iframes is that an iframe can be used to include pages on your website into external sites.
How do you prevent pages on your website from being included through an iframe by another website?
Placing the following javascript code at the top of all pages on your site will ensure that if any other site iframes a page on your website, that your page will break out of the iframe and just display your page in the users browser.
<script type="text/javascript">
<!--
if (top.location!= self.location) {
top.location = self.location.href
}
//-->
</script>
The best way to implement this break out of an iframe code on an entire site is to put the code into an external javascript file, and include it in a common template file (i.e. header template file that is included by all pages on your website).
A working example of how to break out of an iframe. You will be redirected to http://usabledesigns.com/demo/iframe-content if you have javascript enabled in your browser. You can view the original page by turning off javascript in your browser.
The only downfall with this approach to breaking out of Iframe's is when a user has javascript disabled / unsupported in their browser.
Tested in Firefox, IE5 - IE7, and Konqueror.
For assistance with adding this to your website or for any other website development services, please contact UsableLayout.
Comments
Thanks this worked great for
Thanks this worked great for me! - Eric
Thanks for a very helpful
Thanks for a very helpful piece of information!
Additionally I have a question to you. Is there a less "brutal" possibility to break out an iframe? Imagine there is an iframe B inside an iframe A. Is there a probability to break out of the iframe B, but still to stay in iframe A?
Thank you in advance!
Best regards,
Daniel
No ... not possible. This
No ... not possible. This coding will simply keep doing its magic until completely free. Going from iframe B to iframe A then out.
The one exception to this is when Javascript has been disabled, which, sadly, more and more firewall and AV programs are permitting.
Post new comment