How to break out of an iframe

So someone’s trying to make their site better by opening a page on your site inside of their site using an iframe?

They’re doing something like this:

<iframe src="http://www.example.com/your_page.html" width="100%" height="100%"></iframe>

Well how about you stop that from happening by pasting the following line in your website’s header!

<script type="text/javascript">
if (top.location != self.location) {
  top.location = self.location.href;
}
</script>

The above code basically does a check to see if the site is the same as what is said in the address bar, if not then it sets the parent’s frame (the other site) to change to your site’s location!

Make sure to paste that just before the closing </head> tag near the top of your source code.

0 0 vote
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments