How to Automatically Break Out of iframes Using JavaScript

Posted by Lasantha Bandara File Under : html, java script 0 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>

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.