PDA

View Full Version : Stopping iframe for some sites


Lukehall2002
11-24-2002, 04:20 PM
hi everyone!
Recently a person i know has been using i frames to display pages of my site inside his! this is really annoying me!

what script can i use to block access from his site!?

i guess i need to check the top.location and redirect if the value is not true.

thankyou
:)

x_goose_x
11-24-2002, 04:48 PM
This will make it so this page cannot be put in any frames (inline or ortherwise).


<script language="Javascript"><!--

if (top.location != self.location) {
top.location = self.location.href;
}

//--></script>


If you want it in frames on your site, but not work on his/hers you'll need:


<script language="Javascript"><!--

frmpage = "http://www.mysite.com/framepage.htm";

if (top.location != frmpage) {
top.location = frmpage;
}

//--></script>

Lukehall2002
11-24-2002, 10:40 PM
thats great. ive tried to edit the code to redirect if the page is not shown in an iframe of one of 2 sites.

this is what i tried but it always redirects??? even when it shouldn't


<script language="Javascript"><!--

class2001 = "http://example-mysite2.com";
tiscali = "http://example-mysite2.com";
goawayalz = "http://example-mysite1.com/accessdenied.html";
isitalz = "1";

if (top.location = class2001) {
isitalz = "0";
}

if (top.location = tiscali) {
isitalz = "0";
}



if (isitalz = "1") {
top.location = goawayalz;
}

//--></script>


im very new to javascripts, its probably all wrong

thanks:cool:

x_goose_x
11-24-2002, 11:37 PM
You cant use:
if (top.location = class2001) {
you need 2 "=" signs:
if (top.location == class2001) {

but in any case use:


<script language="Javascript"><!--

accepted_sites = new Array();
accepted_sites[0] = "http://example-mysite1.com/framepage.htm";
accepted_sites[1] = "http://example-mysite2.com/frames.htm";
goawayalz = "http://example-mysite1.com/accessdenied.html";

isitalz = "1";

for (x in accepted_sites) {
if (top.location == accepted_sites[x]) {
isitalz = "0";
}
}



if (isitalz = "1") {
top.location = goawayalz;
}

//--></script>