PDA

View Full Version : HELP with Using Frames


learnscripts
11-13-2002, 11:19 AM
hello, my homepage using frames ... the top little one contains the navigation bar, and all the links are targetted to the bottom frame.

It works fine ...

But when i use the search engine, it found the links to the bottom frame ... only display the bottom frame ...

How do I force it to always using frames?

Thanks

kdjoergensen
11-13-2002, 05:08 PM
To do this you need to add a piece of javascript to your frameset and to the individual pages.

To check if a frameset exsists you can put following in the head of each page:


<script language="Javascript" Type="text/javascript">
<!--
if (self.location.href == top.location.href){ // no frames
top.location.href = "http://www.mysite.com/framepage.html";
}
//-->
</script>


However, it will load the home page (framepage.html) into the browser and not the page found on the search engine. To compact this we need to make a change to the above script AND to the frameset document.

Example: lets say this is your normal frameset
framepage.html:

<html>
<frameset rows="100,*">
<frame name="nav" src="nav.html" scrolling=no>
<frame name="cont" src="index2.html">
</frameset>
</html>


Lets change it:

<html>
<frameset rows="100,*">
<frame name="nav" src="nav.html">
<script language="javascript" type="text/javascript">
<!--
// dynamically writing the second frame
if (top.location.search){
var page = top.location.search.substring(1);
var page = unescape(page); // convert characters
document.write('<frame name="cont" src="'+page+'">');
} else {
document.write('<frame name="cont" src="index2.html">');
}
//-->
</script>
</frameset>


above script will dynamically write the 2nd frame tag. if a search string is found in the url (e.g. framepage.html?http://www.mysite.com/dir/page44.html for example) then it will extract and put that url into the src attribute of the frame. If not it will print our usual "index2.html" page as the source.

Ok, where does the search string come from then ?
from the individual pages, of course:


<script language="Javascript" Type="text/javascript">
<!--
if (self.location.href == top.location.href){
var thisPage = self.location.href;
thisPage = escape(thisPage);
// write search string to url
top.location = "http://www.mysite.com/framepage.html?"+thisPage;
}
//-->
</script>


The escape/unescape functions are used to convert illegal characters for use in the address bar.

learnscripts
11-14-2002, 09:43 AM
i tried the codes but it doesn't work ...

running framepage.html will show me only the frame on top, the bottom one is just a gray area, w/out any error message (page not found ....etc.) ... it's supposed to show the index2.html

running the individual page won't show me the frame on top even i added the codes you gave ... i only see the top page ... not in frame

:-(