Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Firefox history.go(-1) not working as needed

Reply
Thread Tools

Firefox history.go(-1) not working as needed

 
 
Raffi
Guest
Posts: n/a
 
      06-23-2007
Hi,

My web page has an iframe with a list of items from a database. These
items are html links and when clicked they execute a server side
script to update the database and reload the iframe with the updated
links. The list is sometimes long and I would like the user to return
to the same iframe anchor point as they were before. I use the
following code in the database update script (which also reloads the
iframe) which works fine with Internet Explorer but returns the user
to the top of the iframe with Firefox.

window.history.go(-1);

Any ideas/suggestions on how to get the desired behavior in both IE
and Firefox?

Thanks,
Raffi

 
Reply With Quote
 
 
 
 
ASM
Guest
Posts: n/a
 
      06-23-2007
Raffi a écrit :
>
> Any ideas/suggestions on how to get the desired behavior in both IE
> and Firefox?


location.href=self.location; ?

or links in normal html ?

<p><a href="?feature=001#f001" name="f001">feature 001</a>
<p><a href="?feature=002#f002" name="f002">feature 002</a>
<p><a href="?feature=003#f003" name="f003">feature 003</a>

--
Stephane Moriaux et son (moins) vieux Mac
Stephane Moriaux and his (less) old Mac already out of date
 
Reply With Quote
 
 
 
 
Raffi
Guest
Posts: n/a
 
      06-23-2007
On Jun 23, 2:40 pm, ASM <(E-Mail Removed)>
wrote:
> Raffia écrit :
>
>
>
> > Any ideas/suggestions on how to get the desired behavior in both IE
> > and Firefox?

>
> location.href=self.location; ?
>
> or links in normal html ?
>
> <p><a href="?feature=001#f001" name="f001">feature 001</a>
> <p><a href="?feature=002#f002" name="f002">feature 002</a>
> <p><a href="?feature=003#f003" name="f003">feature 003</a>
>
> --
> Stephane Moriaux et son (moins) vieux Mac
> Stephane Moriaux and his (less) old Mac already out of date


I tried location.href=self.location; and it resulted in an endless
loop. The anchored link will not work since it's not the linkthat
reloads the iframe but the script that is executed when the user
clicks the link. Here are more details. The main page has an iframe
which has a number of links like the following:

<a href="javascript:window.location.href = './script.xxx?
varable=choice1>Choice1</A>

script.xxx then updates the database using the variable and reloads
the iframe content. Currently

parent.history.go(-1);

works fine for IE but not for Firefox.

Any help will be appreciated.

Thanks,
Raffi

 
Reply With Quote
 
ASM
Guest
Posts: n/a
 
      06-24-2007
Raffi a écrit :
>
> I tried location.href=self.location; and it resulted in an endless
> loop.


Not very surprised

> The anchored link will not work since it's not the link that
> reloads the iframe but the script that is executed when the user
> clicks the link. Here are more details. The main page has an iframe
> which has a number of links like the following:
>
> <a href="javascript:window.location.href = './script.xxx?
> varable=choice1>Choice1</A>


I do not understand where is the script (JS script) ?

Youre 'JS' script 'window.location' is exactly same as :

<a href="./script.xxx?varable=choice1">Choice1</A>

What is what I proposed,
except I've introduced anchors in links AND in calls

<a href="./script.xxx?variable=choice1#choice1" name="choice1" >Choice1</A>


If you want absolutely to use JS :

<a href="./script.xxx" name="choice1"
onclick="this.href+='?variable='+this.name+'#'+thi s.name;">Choice1</A>

or :

<script type="text/javasccript">
window.onload = function() {
var L = document.links;
for(var i=0; i<L.length; i++)
if(L[i].href.indexOf('script')>0)
L[i].href += '?variable='+L[i].name+'#'+L[i].name;
}
</script>

<a href="./script.xxx" name="choice1">Choice 1</A>
<a href="./script.xxx" name="choice2">Choice 2</A>
<a href="./script.xxx" name="choice3">Choice 3</A>

--
Stephane Moriaux et son (moins) vieux Mac
Stephane Moriaux and his (less) old Mac already out of date
 
Reply With Quote
 
Raffi
Guest
Posts: n/a
 
      06-24-2007
On Jun 24, 6:16 am, ASM <(E-Mail Removed)>
wrote:
> Raffia écrit :
>
>
>
> > I tried location.href=self.location; and it resulted in an endless
> > loop.

>
> Not very surprised
>
> > The anchored link will not work since it's not the link that
> > reloads the iframe but the script that is executed when the user
> > clicks the link. Here are more details. The main page has an iframe
> > which has a number of links like the following:

>
> > <a href="javascript:window.location.href = './script.xxx?
> > varable=choice1>Choice1</A>

>
> I do not understand where is the script (JS script) ?
>
> Youre 'JS' script 'window.location' is exactly same as :
>
> <a href="./script.xxx?varable=choice1">Choice1</A>
>
> What is what I proposed,
> except I've introduced anchors in links AND in calls
>
> <a href="./script.xxx?variable=choice1#choice1" name="choice1" >Choice1</A>
>
> If you want absolutely to use JS :
>
> <a href="./script.xxx" name="choice1"
> onclick="this.href+='?variable='+this.name+'#'+thi s.name;">Choice1</A>
>
> or :
>
> <script type="text/javasccript">
> window.onload = function() {
> var L = document.links;
> for(var i=0; i<L.length; i++)
> if(L[i].href.indexOf('script')>0)
> L[i].href += '?variable='+L[i].name+'#'+L[i].name;
> }
> </script>
>
> <a href="./script.xxx" name="choice1">Choice 1</A>
> <a href="./script.xxx" name="choice2">Choice 2</A>
> <a href="./script.xxx" name="choice3">Choice 3</A>
>
> --
> Stephane Moriaux et son (moins) vieux Mac
> Stephane Moriaux and his (less) old Mac already out of date


Hello Stephane,

Thanks for your response and suggestions. It helped me clean up my
html code a little.

Your suggestions for the anchor did not work however. I think the
reason is the anchor information in the html link is passed along to
script.xxx. Once this script runs the "window.history.go(-1);" at the
end of the script does the reloading of the iframe. I think I need
something in script.xxx to make the iframe scroll to the anchor after
reloading.

Thanks,
Raffi

 
Reply With Quote
 
ASM
Guest
Posts: n/a
 
      06-25-2007
Raffi a écrit :
>
> Your suggestions for the anchor did not work however. I think the
> reason is the anchor information in the html link is passed along to
> script.xxx.


Isn't script.xxx a file (a php file whom script does something) ?

> Once this script runs the "window.history.go(-1);" at the
> end of the script


Why do you keep this JS in your file 'script.xxx' ?
You don't need it with the attached anchor (#choicexx)

I do not understand why you have to go back ...
'script.xxx' can't content what that is to display ?

The clicked link calls the file 'script.xxx'
with attached to its url :
- the variable and ist value : ?variable=choicexx
and
- the anchor to reach on (re)loading : #choicexx

It is simple and normal html feature

> I think I need
> something in script.xxx to make the iframe scroll to the anchor after
> reloading.


on reloading you only need to reach the mentioned anchor

Try this example
- where the file calls itself instead to call another file
(isn't it this file which is the src of iframe ?)
- where there is a (JS) script about the attached variable

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled</title>
<style type="text/css" title="text/css">
div p { height: 150px; border: 1px solid; margin-top: 50px; }
</style>
<script type="text/javascript">
onload = function() {
alert(window.location.search);
}
</script>
</head>
<body>
<div>
<p><a href="?feature=256#f256" name="f256">feature 256</a>
<p><a href="?feature=001#f001" name="f001">feature 001</a>
<p><a href="?feature=002#f002" name="f002">feature 002</a>
<p><a href="?feature=003#f003" name="f003">feature 003</a>
<p><a href="?feature=004#f004" name="f004">feature 004</a>
<p><a href="?feature=005#f005" name="f005">feature 005</a>
<p><a href="?feature=006#f006" name="f006">feature 006</a>
<p><a href="?feature=007#f007" name="f007">feature 007</a>
</div>
</body>
</html>



--
Stephane Moriaux et son (moins) vieux Mac
Stephane Moriaux and his (less) old Mac already out of date
 
Reply With Quote
 
The Magpie
Guest
Posts: n/a
 
      06-25-2007
Raffi wrote:
> Hi,
>
> My web page has an iframe with a list of items from a database. These
> items are html links and when clicked they execute a server side
> script to update the database and reload the iframe...
>
> window.history.go(-1);
>
> Any ideas/suggestions on how to get the desired behavior in both IE
> and Firefox?
>

The history refers to web pages loaded within the browser. The loading
of an iframe from the server to an area within the web page does not
change the web page that was loaded, therefore the history does not
record the change of the update. This is as it ought to be and, if it
does not work that way in MSIE then I am afraid that IE is wrong and
Firefox is right. You are dealing with it on your server and it is
your server that should permit the reloading of the previous iframe
contents, not the browser page code in Javascript.
 
Reply With Quote
 
Raffi
Guest
Posts: n/a
 
      06-26-2007
On Jun 24, 6:13 pm, ASM <(E-Mail Removed)>
wrote:
> Raffia écrit :
>
>
>
> > Your suggestions for the anchor did not work however. I think the
> > reason is the anchor information in the html link is passed along to
> > script.xxx.

>
> Isn't script.xxx a file (a php file whom script does something) ?
>
> > Once this script runs the "window.history.go(-1);" at the
> > end of the script

>
> Why do you keep this JS in your file 'script.xxx' ?
> You don't need it with the attached anchor (#choicexx)
>
> I do not understand why you have to go back ...
> 'script.xxx' can't content what that is to display ?
>
> The clicked link calls the file 'script.xxx'
> with attached to its url :
> - the variable and ist value : ?variable=choicexx
> and
> - the anchor to reach on (re)loading : #choicexx
>
> It is simple and normal html feature
>
> > I think I need
> > something in script.xxx to make the iframe scroll to the anchor after
> > reloading.

>
> on reloading you only need to reach the mentioned anchor
>
> Try this example
> - where the file calls itself instead to call another file
> (isn't it this file which is the src of iframe ?)
> - where there is a (JS) script about the attached variable
>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
> <html xmlns="http://www.w3.org/1999/xhtml">
> <head>
> <title>Untitled</title>
> <style type="text/css" title="text/css">
> div p { height: 150px; border: 1px solid; margin-top: 50px; }
> </style>
> <script type="text/javascript">
> onload = function() {
> alert(window.location.search);
> }
> </script>
> </head>
> <body>
> <div>
> <p><a href="?feature=256#f256" name="f256">feature 256</a>
> <p><a href="?feature=001#f001" name="f001">feature 001</a>
> <p><a href="?feature=002#f002" name="f002">feature 002</a>
> <p><a href="?feature=003#f003" name="f003">feature 003</a>
> <p><a href="?feature=004#f004" name="f004">feature 004</a>
> <p><a href="?feature=005#f005" name="f005">feature 005</a>
> <p><a href="?feature=006#f006" name="f006">feature 006</a>
> <p><a href="?feature=007#f007" name="f007">feature 007</a>
> </div>
> </body>
> </html>
>
> --
> Stephane Moriaux et son (moins) vieux Mac
> Stephane Moriaux and his (less) old Mac already out of date


Hi,

script.xxx does not display anything. It is called by the link in the
iframe to update the database. Once it is done updating the database,
it returns the user back to the iframe script to display the iframe
with the updated database content. So if script.xxx did not reload the
iframe script, the iframe would remain blank.

So the question remains. Is there a way to reload the iframe script
from script.xxx where the iframe will scroll down to where the client
clicked the link. This can be accomplished with IE using
history.go(-1), but doesn't work for Firefox.

Any help is greatly appreciated.

Thanks,
Raffi

 
Reply With Quote
 
Raffi
Guest
Posts: n/a
 
      06-26-2007
On Jun 25, 9:45 pm, Raffi <(E-Mail Removed)> wrote:
> On Jun 24, 6:13 pm, ASM <(E-Mail Removed)>
> wrote:
>
>
>
>
>
> > Raffia écrit :

>
> > > Your suggestions for the anchor did not work however. I think the
> > > reason is the anchor information in the html link is passed along to
> > > script.xxx.

>
> > Isn't script.xxx a file (a php file whom script does something) ?

>
> > > Once this script runs the "window.history.go(-1);" at the
> > > end of the script

>
> > Why do you keep this JS in your file 'script.xxx' ?
> > You don't need it with the attached anchor (#choicexx)

>
> > I do not understand why you have to go back ...
> > 'script.xxx' can't content what that is to display ?

>
> > The clicked link calls the file 'script.xxx'
> > with attached to its url :
> > - the variable and ist value : ?variable=choicexx
> > and
> > - the anchor to reach on (re)loading : #choicexx

>
> > It is simple and normal html feature

>
> > > I think I need
> > > something in script.xxx to make the iframe scroll to the anchor after
> > > reloading.

>
> > on reloading you only need to reach the mentioned anchor

>
> > Try this example
> > - where the file calls itself instead to call another file
> > (isn't it this file which is the src of iframe ?)
> > - where there is a (JS) script about the attached variable

>
> > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
> > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
> > <html xmlns="http://www.w3.org/1999/xhtml">
> > <head>
> > <title>Untitled</title>
> > <style type="text/css" title="text/css">
> > div p { height: 150px; border: 1px solid; margin-top: 50px; }
> > </style>
> > <script type="text/javascript">
> > onload = function() {
> > alert(window.location.search);
> > }
> > </script>
> > </head>
> > <body>
> > <div>
> > <p><a href="?feature=256#f256" name="f256">feature 256</a>
> > <p><a href="?feature=001#f001" name="f001">feature 001</a>
> > <p><a href="?feature=002#f002" name="f002">feature 002</a>
> > <p><a href="?feature=003#f003" name="f003">feature 003</a>
> > <p><a href="?feature=004#f004" name="f004">feature 004</a>
> > <p><a href="?feature=005#f005" name="f005">feature 005</a>
> > <p><a href="?feature=006#f006" name="f006">feature 006</a>
> > <p><a href="?feature=007#f007" name="f007">feature 007</a>
> > </div>
> > </body>
> > </html>

>
> > --
> > Stephane Moriaux et son (moins) vieux Mac
> > Stephane Moriaux and his (less) old Mac already out of date

>
> Hi,
>
> script.xxx does not display anything. It is called by the link in the
> iframe to update the database. Once it is done updating the database,
> it returns the user back to the iframe script to display the iframe
> with the updated database content. So if script.xxx did not reload the
> iframe script, the iframe would remain blank.
>
> So the question remains. Is there a way to reload the iframe script
> from script.xxx where the iframe will scroll down to where the client
> clicked the link. This can be accomplished with IE usinghistory.go(-1), but doesn't work for Firefox.
>
> Any help is greatly appreciated.
>
> Thanks,Raffi- Hide quoted text -
>
> - Show quoted text -


I figured out a way to get it done using cookies. Below are functions
to create a cookie, read a cookie and delete a cookie, as well as to
get the scroll position of a page and scroll a page to a known
position. The way it works is pretty simple.

1. Get the vertical scroll position
2. Store it in a cookie
3. Run script.xxx
4. Reload the iframe
5. Retrieve the scroll position from the cookie
6. Scroll the iframe to the correct position

Here are the functions:

function createCookie(name, value, days)
{
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name)
{
var ca = document.cookie.split(';');
var nameEQ = name + "=";
for(var i=0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1, c.length); //delete
spaces
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,
c.length);
}
return null;
}

function eraseCookie(name)
{
createCookie(name, "", -1);
}

function setScroll(){
var yScrollTo = readCookie('testCookie');
if(yScrollTo){
window.scrollTo(0,yScrollTo);
eraseCookie('testCookie');
}
}


function saveScroll(){
if(typeof(window.pageYOffset)=="number"){
y=window.pageYOffset;
}else{
y=document.body.scrollTop;
}
createCookie('testCookie', y, 3);
}

And for the body of the iframe:

<body onclick="saveScroll()" onLoad="setScroll()">

Raffi

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help: Javascript not working in Firefox "event not defined" Wiseman Javascript 1 07-25-2008 03:04 PM
EJB3 Help needed: @PrimaryKeyJoinColumn not working Dave Java 2 11-09-2007 06:58 PM
script not working in Firefox (variable is not defined) ORF3O Javascript 2 10-14-2005 11:14 AM
wifi not working on new hp, or not working after live update =?Utf-8?B?RHJhZ29ueA==?= Wireless Networking 1 10-01-2005 11:17 PM
Help needed !! Permanent cookies not working Raghu Raman ASP .Net 3 05-07-2005 12:31 AM



Advertisments