Click to See Complete Forum and Search --> : Navigation menu without server-side scripts.


basis
11-06-2003, 08:18 AM
Hi All!
I am a novice at JavaScript developing. I develop simple web site. The site is hosted on a server where server-side scripts are disabled. I needed to implement navigation menu on the site. I didn’t want to duplicate menu code in all HTML file so I putted menu code in separate frame. Everything worked well but when a user found one of the site pages by search mashine the page was opened without menu frame. So I added to all HTML file following body OnLoad Java Script handler.

function ShowMenu()
{
var sBody = "<frameset rows='50,*' Border = 0>" +
"<frame src=menu.htm ' name='frmMenu' noResize = 'true' scrolling = 'no' >" +
"<frame src=" +
self.location.href +
" name='frmContent'>" +
"</frameset>";
return sBody;
}


// Body OnLoad handler
function CheckMenu()
{
if (!window.parent.frames.length)
{
self.location.href = "java script:ShowMenu()";
}
}

Now script loads menu if anybody tries to open page without frames. But error “The page cannot be displayed” appears if I try to reload (F5) page in IE 6.0. IE address bar contains “java script:ShowMenu()” after that. How can I solve the problem? Maybe is there a solution to add menu without duplication code and without frames?

requestcode
11-06-2003, 11:03 AM
You might want to use the code below to force the page into your frameset when that happens. First place this code in the head section of each document:
<script language="JavaScript">
if (self == top)
{
var url = self.location;
self.location = "http://www.mysite.com/frset.html?" + url;
}
</script>

Change the above URL to what ever your site domain is and also what your frame set document name is. Then in your frame set use the following code:

<html>
<head>
<title>Frame Print Demo</title>
<script language="JavaScript">
function frame_saver()
{
if (self.location.search)
{
parent.frameb.location = location.search.substring(1,location.search.length);
}
}
window.onload = frame_saver;
</script>
</head>
<frameset rows="25%,*" border="1">
<frame src="looka.html" name="framea">
<frame src="lookb.html" name="frameb">
</frameset>

For the above make sure that your frame that you "force" the page into has a default document.

What happens with these two scripts is the first one detect that the document is not in a frame and redirects to your frame set with the URL of the document attached. The next set of code in your frameset looks for that URL and then loads the document into the specified frame. If there is nothing attached to the URL then it will do nothing using your default document. Hope this makes sensea and good luck.