Forum Moderators: open

Message Too Old, No Replies

Frames, Javascript & the Back Button

'wrong' frame loaded when using back button

         

Darkelve

9:22 am on Dec 29, 2005 (gmt 0)

10+ Year Member



A friend of mine asked to look at a problem of his: he is making a website with plenty use of frames. When a link is choosen, through Javascript the necessary links for ALL the frames are choosen. E.g. If by clicking a link, all 4 frames need to change, a javascript called '4links' is launched, replacing all frame content with the 'proper' links.

However, when when using the back button this gives weird behavior: often other parts then the main content go '1 page back'.

Now I'm redesigning the thing with nice&clean html&css, since it's a really simple website.

But what I want to know is: is there a possible quick-fix so that only the content gets back 1 page in the history?

Here is the code for the frameset and 1 contentpage; pay special attention to the Javascript:

FRAMESET


<html>
<head>
<meta http-equiv="Content-style-type" content="text/css"; charset="iso-8859-1">
<title>test</title>
<link rel="stylesheet" href="css/test.css" type="text/css">
</head>
<frameset rows="8%,9%,76%,7%">
<frame src=logo.html name="logo" frameborder="no" framespacing="0">
<frame src=content.html name="contenttable" frameborder="no" framespacing="0">
<frameset cols="13%,87%">
<frameset rows="70%,30%">
<frame src=subcontent_1.html name="sub" frameborder="no" framespacing="0">
<frame src=blanc.html name="blanc" frameborder="no" framespacing="0">
</frameset>
<frame src=intro.html name="field" frameborder="no" framespacing="0">
</frameset>
<frame src=company.html name="companydata" frameborder="no" framespacing="0" scrolling="no">
</frameset>

<noframes>
Browser cannot use frames
</noframes>
</html>

CONTENT PAGE


<html>
<head>
<meta http-equiv="Content-style-type" content="text/css"; charset="iso-8859-1">
<title>test</title>
<link rel="stylesheet" href="test2.css" type="text/css">
<script language="JavaScript">
function 4links(link1, link2,link3, link4)
{
parent.frames['subcontent'].location.href = link1;
parent.frames['field'].location.href = link2;
parent.frames['contenttable'].location.href = link3;
parent.frames['companydata'].location.href = link4;
}

</script>

</head>
<TABLE HEIGHT=100% WIDTH=100% BORDER=0>
<TR ALIGN=LEFT VALIGN=Top CLASS="H1" HEIGHT=5%>
<TD>
Introduction
</TD>
</TR>

<TR HEIGHT=90% ALIGN=LEFT VALIGN=Top>
<TD>Some text
</TD>
</TR>
<TR HEIGHT=5%>
<TD ALIGN=RIGHT VALIGN=Bottom CLASS="talen">
<A HREF="javascript:4links('subcontent_1.html','intro.html','contenttable.html','companydata.html')">NL</A> ¦
<A HREF="javascript:4links('subcontent_fr_1.html','intro_fr.html','contenttable_fr.html','companydata_fr.html')">FR</A> ¦
<A HREF="javascript:4links('subcontent_en_1.html','intro_en.html','contenttable_en.html','companydata_en.html')">EN</A>
</TD>
</TR>

</TABLE>
</BODY>
</html>

Thanks in advance for any tips,

Darkelve

kaled

2:44 pm on Dec 29, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Don't assign to location.href, use location.replace() instead. However, Opera may still not work properly.

Kaled.

topsites

7:53 pm on Dec 29, 2005 (gmt 0)



Do yourself a favor and get rid of the frames, they will eventually (and then continuously) hurt you far beyond this minor location implication.

I know you hate me for saying it, but I speak from experience as I ran frames myself years ago, nothing but trouble in the end, it's just not worth it.

I did find in time, it is possible to build anything without frames, and just as well.

tedster

8:03 pm on Dec 29, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here's a good reference thread about the Pros and Cons of Frames [webmasterworld.com].

I think one problem you smack into with the Back Button is that it depends on how the browser handles History -- and that's a moving target, expecially when multiple frames have been changed with a javascript function. You just can't get consistency,