Link to home
Start Free TrialLog in
Avatar of yck
yck

asked on

How to stop being framed!!!

I have an existing homepage and having problems
with being framed by other websites. For example
when my page is linked from a website using
frames, my page(s) appear as a frame-let.

I would like to know whether there is any HTML
that I can add to prevent this so that my page is
always displayed using the full browser screen
and the location of the URL displayed correctly.

I would prefer a non Java-script solution if
possible. The solution is required for every page
on my site not just the front page. Thanks

Colin

Colin
Avatar of blackEyEz
blackEyEz

<A HREF="mywebpage.html" TARGET="parent"> = Using the whole browser window without frames for mywebpage.html

<A HREF="mywebpage.html" TARGET="_blank"> = Opens a new browser for mywebpage.html
Well, I'm sorry, but no way you can just solve this with plain HTML. However with javascript it can be solved. It's only one function and one onload event handler.

The function :

<script language="javascript">
<!--
function NotFramed(){
if (parent.frames.length != 0) {
  // loaded in frames
window.location.href="http://myurl.com";
}
else {
  // not loaded in frames
}
}
//-->
</script>

then in the onload of the body call this function:

<body onLoad="javascript:NotFramed();">

Now, if the page is loaded in frames, it goes to the defined url else nothing...

This must do the trick ;)

Joseph
ASKER CERTIFIED SOLUTION
Avatar of knightEknight
knightEknight
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Based on BlackEyEz' solution: add <BASE TARGET="_top"> to every page on your website, between the </HEAD> and <BODY> tags. This won't keep the pages from being framed, but any hyperlink clicked from your page will automatically load over any framesets -- so you'll never be framed more than once.

If you want your pages to never be framed at all, then you need to use one of the JavaScript solutions posted here.
no mblaze.....You don't wanna do that!

if You do it like that You will get every page loading without the frameset.

The only possible solution is to (in the frameset page) detect (using javascript) whether Your frameset is at the top of the frameset..if it isn't jump out and display it as it should be..

actually this is pretty simple...

just use:

<script language="javascript">
<!--
if window.location != '<Your URL>'
  {
    top.location.replace('<Your URL>');
  }
//-->
</script>

that should do the trick, it does for me... i couldn't help myself...i HAD to respond to this...

good luck..
Avatar of yck

ASKER

knightEknight's answer seems the best as it works and satifies my requirements.. Plus its just an
extra line on each page :8)

<HTML>
<HEAD>
<SCRIPT language='javascript'> window.name = "ThisIsMYWindow"; if ( top.name != window.name ) { top.location = self.location.href; } </SCRIPT>
<TITLE>hello world</TITLE>
</HEAD>
hello


hello buddy
</HTML>
with my code You would have lost another line...and it's just as easy, but i guess my answer came to late...sorry will respond sooner next time....

Max out!
Yep, I agree, knight's the winner here...

Joseph
No, <b>dream</b> is the winner here..:)
Avatar of yck

ASKER

Hello, I still think knightEknight still wins because
DreamMaster's requires hardwiring the URL
within the webpage. This can be a problem if you
develope your page off-line or have mirror sites.

This is the sort of coding I'll use where window.name
MUST be reset to a different value for each page.
If this is not done the second page on my site can
be reframed again. I suppose each webpage should
have its own "tag" such as something to do with
its filename for example.

Thanks all for your help.

<HTML>
<HEAD>
<SCRIPT language='javascript'> window.name = "page1"; if ( top.name != window.name ) { top.location = self.location.href; } </SCRIPT>
<TITLE>hello world</TITLE>
</HEAD>
hello
<A HREF="page2.htm">click</A>

hello buddy
</HTML>
Hey, but mine wasn't bad either ;)