JavaScript: Break Frames


Introduction

Author: Martin Warning
Year: 2007
License: Free

Page hijacking is something that can happen to your pages. Page hijacking is when another site loads your pages inside their frames, thus making the user believe your content belongs to another site. A simple JavaScript code can solve this issue.

Code

Languages: The following code is an example frame break:
<script language="javascript">
	//<![CDATA[
	if (parent.location.href != self.location.href) {
	window.location.href = self.location.href;
	}
	// End -->
	//]]>
</script>

In this example we compare the parent location url value and compare it with the url value of our own page. If the 2 are not the same we open our page in place of the frame, thus busting out of the frame.



Printed from: http://flyinglowlander.com/ (5/20/2012)
© FlyingLowander.com 2006 - 2012

Visit http://flyinglowlander.com for more XHTML, CSS, ASP and JavaScript examples, templates and tutorials.