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
yckAsked:
Who is Participating?
 
knightEknightConnect With a Mentor Commented:
You might try something like this:

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


0
 
blackEyEzCommented:
<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
0
 
oubelkasCommented:
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
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
mblaseCommented:
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.
0
 
DreamMasterCommented:
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..
0
 
yckAuthor Commented:
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>
0
 
DreamMasterCommented:
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!
0
 
oubelkasCommented:
Yep, I agree, knight's the winner here...

Joseph
0
 
blackEyEzCommented:
No, <b>dream</b> is the winner here..:)
0
 
yckAuthor Commented:
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>
0
 
oubelkasCommented:
Hey, but mine wasn't bad either ;)
0
All Courses

From novice to tech pro — start learning today.