Thursday 12 July 2012

JavaScript: avoid frames

   


There's one thing that I really can't stand: when, redirected from a site, the destination page is included in a frame. You surely have experienced the situation and you may understand how much I hate it.
Anyway, there's a quick and easy solution for that using JavaScript.
In this - very - short post, I will show you how to do it.

This is indeed a short solution. In fact, as you will see, we only need to add a small function and a line to the body tag. First of all the function: just put it in the head of your document.
<head>
<script language="JavaScript" type="text/javascript">
<!--
function avoid_frame()
{
  if (top.location != location) {
    top.location.href = document.location.href ;
  }
}
-->
</script>
</head>
Straight and simple.
You can even put the function in a .js file, and include it in all your documents. Doing so, you don't need to change it every time in every page.
Ok. Now we need to call the function.
To do so we just change our body tag to:
<body onload="avoid_frame()">
and that is all.

It seems that the above solution, even if quite effective, in certain situations is not enough.
I don't want to re-write something that was already discussed in the past. So, if you're interested in understanding the situation a bit further, please visit the anti anti frame busting page.

Still working and ready for vacation...




0 thoughts:

Post a Comment

Comments are moderated. I apologize if I don't publish comments immediately.

However, I do answer to all the comments.