I am redirecting any page that is not in frame to index.html. The index is being changed to index.html?page.html
I want to use the additional part from address and set the SRC of the frame to this value.
I don't know how to include location.search.substring(1)
correctly so it wouldn't cause errors.
Each site has code:
if (top.location == self.location)
{
top.location = 'index.html?' + location.href.replace(/^.*[\\\/]/, '');
}
The index page contains right after
<frameset rows="100px,100%" cols="*" border="0">
<frame src="logo.html" name="logo" scrolling="no">
<frameset rows="*" cols="200,100%" border="0">
<frame src="menu.html" name="menu" scrolling="no">
<script language="javascript">
if (location.search && location.search.length > 1 && location.search.charAt(0) == "?")
{
document.write('<frame src="' + location.search.substring(1) + '" name="page" scrolling="auto">');
}
else
{
document.write('<frame src="main_page.html" name="page" scrolling="auto">');
}
</script>
</frameset>
</frameset>
I got this idea from my previous question.
BTW. Should I even do this? Is there any better solution?
The idea is allright, if you want to use frames. Lonely pages purposed to be shown in the frames often need something from other frames or top.window. Working solution:
1) No script into
frameset
-tags is needed.2) Redirect the page:
3) create a fake page to load to
page
-frame and put there a script, which retrieves the URL of the top.window. Then redirect the fake page to the page where user earlier was. If the original page was your index.html, then just load the right page. That script can also be put to the document inmenu
-frame, but then you have to wait untill all frames are fully loaded before redirecting.Notice, results what you will get from
location
object's properties, varies depended on browser. Hence avoid literal comparing and manipulating of the URLs, uselocation
-object's properties only.OK, here is a simple example. I think a lot of more sophisticated solutions exist, but the example contains all basic stuff for a task. A fake page is not needed also.
I've tested this locally only, and Chrome redirects just to the frontpage. Other browsers (FF, IE, Opera) work as expected.
1) Rewrite your index.html as normal frameset (that is: no
document.write
s)2) Put this script in the
head
of index.html3) Put this script in the
head
of your frontpage4) Put this script in the
head
of all other pages (not in index.html)Your homework is, how to get Chrome to do this right, if it fails with real http-pages.