Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove frames automatically

Status
Not open for further replies.

MartinCouture

Technical User
Feb 16, 2002
57
CA
My extend of Javascript is at the cut and past level, so here I go :


<html>
<head>
<SCRIPT LANGUAGE=&quot;JavaScript1.2&quot;>
<!-- Begin
function enleverframes(){
nombreframes=parent.frames.length;
if (nombreframes>0){
parent.location.href=self.location.href;
}

}
// End -->
</SCRIPT>

<title>Herc.zapto.org</title>
<meta name=&quot;GENERATOR&quot; content=&quot;Notepad ;-D&quot;>
<meta name=&quot;ProgId&quot; content=&quot;FrontPage.Editor.Document&quot;>
</head>
<frameset rows=&quot;70,*&quot; FRAMEBORDER=&quot;no&quot; BORDER=0>
<frame src=&quot;top.html&quot; name=&quot;top&quot; id=&quot;top&quot; frameborder=&quot;0&quot; scrolling=&quot;No&quot; noresize marginwidth=&quot;0&quot; marginheight=&quot;0&quot; bordercolor=&quot;#000000&quot; target=&quot;menu&quot;>
<frameset cols=&quot;170,*&quot; FRAMEBORDER=&quot;no&quot; BORDER=0>
<frame src=&quot;menu.html&quot; name=&quot;menu&quot; id=&quot;menu&quot; frameborder=0 scrolling=&quot;No&quot; noresize bordercolor=&quot;#000000&quot; target=&quot;main&quot;>
<frame src=&quot;main.html&quot; name=&quot;main&quot; id=&quot;main&quot; frameborder=0 scrolling=&quot;Auto&quot; bordercolor=&quot;#000000&quot; target=&quot;_self&quot;>
</frameset>
<noframes>
<body onLoad=&quot;enleverframes();&quot;>
<p>This web pages uses frames. You browser cannot display them correctly.
Please upgrade your browser</p>
<p>Cette page utilise des cadres, mais votre navigateur ne les prend pas en
charge.</p>

</body>
</noframes>
</frameset>
</html>


I would like this index.html page, which contains 3 frames, to load at the top level. Because Spaceports has a link to my site and they leave a footer containing adds, I would like this page to check to see if it is in a frame, and if it is, to load at the &quot;_top&quot; level...

This pages loads ok, but does not remove the frame ! The script is a cut and paste from a magazine and it looks like it makes sense, but I'm not sure where I'm supposed to put the code and the onload command is in the <BODY> part which, I think, won't be loaded unless the browser doesn't support frames.

Thanks :)
 
Place this into the <head> of your page:

<meta http-equiv=&quot;window-target&quot; content=&quot;_top&quot;>

 
hmm...
I tried testing starway's solution, and for me, it didn't seem to work.

So, I'll post the code that I tested working.
Code:
<base target=&quot;_top&quot;>
in the <head> will make all links by default target _top.


Here's to break out of frames when the page loads:
Code:
<script type=&quot;text/javascript>
<!--
if (top.location.href != location.href)
 top.location.href=location.href;
// -->
</script>



Put it in the <head>
bluebrain.gif
blueuniment.gif
 
Well, after testing for 2 hours(!), the META tag didn't work and the Script works ... BUT

It doesn't work when I call the page with:
header(&quot;Location: in a php sctipt... I get a Permission denied and gives me the line number where the if (top.location.href starts. I'll ask the php forum why...

It works perfectly otherwise. That's why I couldn't figure out why it worked in a test page with a normal <a> tag and then not work from the real link <? php checking stuff and then header... for redirect ?>

So in Javascript, I would like to test the cookie value of choice which contains the web link to a page, and then redirect the browser to that page, _top as target.

Thanks starway & Uniment...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top