Javascript: Prevent page from frameset hijack
If you would like to prevent your site being frame by other website, you can use the code below to protect your site being frame.
Basically, the javascript check if your site is being open by frameset. It check if the opening window is top or else it will refresh the page to your site URL.
Many unethical site nowdays like to “wrap” other people website using FRAME at their website to show other website as it’s own website. This will mislead the visitor that the content is owned by them.
Frameset prevention script #1
<script type=”text/javascript”>
if (top.frames.length!=0) {
if (window.location.href.replace)
top.location.replace(self.location.href);
else
top.location.href=self.document.href; }
</script>
Frameset prevention script #2
<script type=”text/javascript”>
function breakOut() {
if (self != top)
window.open(”my URL”,”_top”,”");
}
</script>
Frameset prevention script #3
<script>
if (window!=top){top.location.href=location.href;}
</script>
If you think this article helps you to solve your problem and clear your headache, feel free to buy me a drink :)









January 14th, 2008 at 7:42 am
So do i use just one of those methods ? or all 3 ?.. and where do i apply the code ? in the EHad or directly after the BODY tag ??
January 16th, 2008 at 3:06 pm
choose any one from the three methods.
put it between the tag