How to break out of an iframe

0 min read 117 words

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 closingtag near the top of your source code.

Andrew
Andrew

Andrew is a visionary software engineer and DevOps expert with a proven track record of delivering cutting-edge solutions that drive innovation at Ataiva.com. As a leader on numerous high-profile projects, Andrew brings his exceptional technical expertise and collaborative leadership skills to the table, fostering a culture of agility and excellence within the team. With a passion for architecting scalable systems, automating workflows, and empowering teams, Andrew is a sought-after authority in the field of software development and DevOps.

Tags

Recent Posts