Iframe breakout

In: JavaScript

August 20th, 2010.

Sometimes, you don’t want your website to be displayed on other websites inside of an iframe. It is easy to protect your website from being displayed inside of iframe by using following JavaScript iframe breakout snippet:

1
2
3
4
5
6
7
8
<script>
function get_out_of_iframe() {
	if (top.location.href != self.location.href)
		top.location.href = self.location.href;
}
 
window.onload = get_out_of_iframe();
</script>

Written by

Dejan is pragmatic software developer with Master's Degree in Computer Science. He is currently based in Belgrade (Serbia).