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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using history functionality in both NS and IE

Status
Not open for further replies.

ckennerdale

Programmer
Dec 23, 2000
158
GB
I am trying to set up histiry buttons, providing back and forward functionality, controlling another frame.

I can get it to work in both IE and NS, but when I try to combine code for both browsers into a function call LoadVars() - see below, it doesnt work, However I have used this technique before with success- although not with history.

Any ideas?

The code below is the frame containing the buttons-

<html>
<head>
<title>Untitled Document</title>
<script>
function LoadVars(){
if (navigator.appName == &quot;Netscape&quot;){
window = parent.frames[0];
}
else{
window;
}
}
function goBack()
{
window.history.back();
}

function goForward()
{
window.history.forward();
}

</script>

</head>
<body bgcolor=&quot;#FFFFFF&quot; onLoad=&quot;LoadVars()&quot;>
<br>
<br>

<br>
<a href=javascript:goBack();>back</a>-
<a href=javascript:goForward();>forward</a>-
</body>
</html> Caspar Kennerdale
Senior Media Developer
 
I'm not sure if I explaned my self correctly

The top.history.back works fine in IE but in Navigator it doesnt work in frames- The whole page gets replaced!

Basically I need bottom frame to control the back and forward of top frame.

window.history.back() works fine in IE but not Navigator
whereas parent.frames[0].history.back() works in Navigator.

So I thought I use this code which has worked when this type of incompatability has been met before-

<script>
function LoadVars(){
if (navigator.appName == &quot;Netscape&quot;){
window = parent.frames[0];
}
else{
window;
}
}
function goBack()
{
window.history.back();
}

function goForward()
{
window.history.forward();
}

</script>

And then have LoadVars on Body load.

But it just isnt working?

Essentially if the broser is NS then it should replace 'window' with 'parent.frames[0]' and thus make the functons compliant in both browsers!

???? Caspar Kennerdale
Senior Media Developer
 
Why not use parent.frames[0] for both browsers? IE has the frames array too.

Or you could name your frame when you define it.
<frame name=&quot;top_frame&quot; src=&quot;...&quot;>
parent.top_frame.forward();
parent.top_frame.back();
Sincerely,

Tom Anderson
CEO, Order amid Chaos, Inc.
 
parent.frames[0] doesnt seem to work with IE (I'm using 5)

I just get 'Done but with errors' at the bottom of the browser and nothing happens. This is the same if I use parent.&quot;framename&quot;.

parent.frames[0] works with NS
window. works with IE.

So I was hoping to have some kind of function that detected if you were on NS and if so to interpret 'window' as 'parent.frames[0]' and thus the button functions would work.

I have used this technique before, for other things, but it isnt working here. Caspar Kennerdale
Senior Media Developer
 
I've never had any problems like that.

Anyway, I don't think you can rename the window object since that is already declared inherently. Name it something else.

function LoadVars(){
if (navigator.appName == &quot;Netscape&quot;){
var top_frame = parent.frames[0];
}
else{
var tope_frame = window;
}
}

top_frame.history.back();
top_frame.history.forward();
Sincerely,

Tom Anderson
CEO, Order amid Chaos, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top