Welcome to WebmasterWorld Guest from

Forum Moderators: incrediBILL

Message Too Old, No Replies

Defeating Framing

4:52 pm on Sep 8, 2000 (gmt 0)

Administrator from US 

WebmasterWorld Administrator brett_tabke is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Sept 21, 1999
votes: 62

What do you think, is this the best way (compat/easiest) to defeat framing? (eg: we suddenly are getting killer traffic from ask jeeves and I can't deal with being framed. It makes me want to write one of those nasty back button killers under 10 redirects).

<SCRIPT Language="JavaScript">
var real_location = "http://www.yourshere.com/";

function nogojoe () {
if (top.location) {
if (self != top) top.location = self.location;
else {
if (parent.location) {
if (parent.location != real_location) parent.location = real_location;

<BODY onLoad="nogojoe()">

6:35 pm on Sept 9, 2000 (gmt 0)

Senior Member

WebmasterWorld Senior Member tedster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:May 26, 2000
votes: 0

The code I use is:

if (parent != self) top.location.replace("yourpage.html");

I prefer the replace() method because the browser history remains intuitive. However, replace() is JavaScript 1.1. For greater compatibility, this code:

if (parent != self) top.location="yourpage.html";

is entirely JavaScript 1.0. But it does add an extra entry to the browser history.

Once you test to see if there is a parent for your page, the exact window configuration doesn't really matter, as I see it. So this code just says "Do I have a parent? If so, load me at the top level."