How to Automatically Break Out of iframes Using JavaScript

Posted by Lasantha Bandara on February 25th, 2015 File Under : html, java script0 Comment

Iframe stands for inline frame. It is used embed content of a web page inside another web page. An inline frame is marked up as follows:

<iframe src="YOUR_WEB_PAGE_URL"></iframe>

If another website is displaying your website inside an iframe, this little piece of code help you to break out of that iframe and just display your web page in the users browsers.

Add this code just before </head> tag of your site:

<script type='text/javascript'>
//<![CDATA[

(function(window) {
  if (window.location !== window.top.location) {
    window.top.location = window.location;
  }
})(this);

//]]>
</script>

File Under : html, java script

Related Posts

Leave a Reply