Welcome to WebmasterWorld Guest from 3.229.122.166

Forum Moderators: open

Message Too Old, No Replies

a href="javascript:history.go(-1)" suddenly stopped working

     
9:06 am on Sep 4, 2003 (gmt 0)

New User

10+ Year Member

joined:Sept 4, 2003
posts:6
votes: 0


Hi

I've been using a set of images to offer within-frame navigation for some time successfully, with javascript code defining the page destination from clicking the button.

This has worked fine up to now, but one of the images has stopped "working". I can see from looking back at the forum and elsewhere that implementation of the code seems flaky, but can't see why it has spontaneously stopped working when it was fine before.

Some details:
There are 3 frames, a top frame and bottom frame which stay the same and a middle frame that changes to show the site content. The browser is run full-screen on a touch screen console, so the user has no access to keyboard or browser buttons; however, running it NOt in full screen or on a system with keyboard and mouse attached shows that the Browser Back button still works, as does the keyboard Alt-Left arrow. This occurs in IE5 and 5.5, on both Windows 95 and 98 so far, but seems computer specific as it works fine on most computers with identical specifications.

There are two images. One offers the chance to Go Back one page, the other to Return Home. Both display a rollover image. The rollover images both still work. One uses <a href="javascript:printFrames()" target="middle" ~~~ to print the contents of the middle frame, and that one still works. The Problem one uses <a href="javascript:history.go(-1)" ~~~

Dropping down the History list shows no problems with the actual list itself; any ideas on why the javascript:history.go(-1) might suddenly stop working on these computers but not on others?

Any help or suggestions very much appreciated; I've tried lots of things, including repairing IE, clearing History and Temp files, all to no avail and am starting to run out of ideas.

9:35 am on Sept 4, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member tedster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:May 26, 2000
posts:37301
votes: 0


Welcome to WebmasterWorld, Histon.

One thing you can be sure of, the change isn't really "spontaneous". That is, even if you never uncover the exact cause, there is a change of some kind that makes a previously functional area stop functioning.

...full-screen on a touch screen console, so the user has no access to keyboard or browser buttons...seems computer specific as it works fine on most computers with identical specifications

What's the OS and browser of the malfunctioning computers? Is there any chance of some auto-updating going on, that perhaps changed security settings? Are these units networked, virus protected, always online or just local?

Since you still get rollover images, we can assume that javascript is still enabled.

10:47 am on Sept 4, 2003 (gmt 0)

Preferred Member

10+ Year Member

joined:Nov 19, 2002
posts:372
votes: 0


is will never work when target="_self"
because <a href="javascript:"> itself is a "navigate"
try:

<a href="javascript:" onclick="history.go(-1); return false>

11:22 am on Sept 4, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Mar 27, 2003
posts:664
votes: 0


>>>'..."will never work when target="_self" because <a href="javascript:"> itself is a "navigate" "?...'

Xuefer, I am not sure what you mean. Can you clarify. Seems OK to me.

One thing to check is if clearing the cache helps...

12:06 pm on Sept 4, 2003 (gmt 0)

Preferred Member

10+ Year Member

joined:Nov 19, 2002
posts:372
votes: 0


i missed a quote
<a href="javascript:" onclick="history.go(-1); return false">
8:39 pm on Sept 4, 2003 (gmt 0)

New User

10+ Year Member

joined:Sept 4, 2003
posts:6
votes: 0


Hi guys, thanks for the welcome and all the prompt replies.

The computers so far affected are all PCs, running either Windows 95 or 98 with various types of IE 5 to 5.5, some security patched and some not. Some have anti-virus, some don't. None are networked except mine, which hasn't been connected to the network for 6 months. None has had an update or a disk anywhere near it for ages. Mine (which became non-functional for this one feature only late last night after 3 years of working fine!) is the only one I can guarantee the history of (no pun intended); here's the latest.

I now think it is a frames issue that is manifesting in some way. The reason I think this is that I have a couple of buttons actually in the middle frame which use identical code, and they work fine; it is only the ones in the top frame that have stopped working suddenly. I have 3 other computers running Win 98 and IE 5.5 which still function perfectly, so it "can't" be the code. I don't doubt that "something" caused the problem other than spontaneous Sods Law, since the site has been working fine on hundreds of computers of all sorts for 3 years, both on-line, off-line, from CD and from hard drive, and on local network. I'm pretty sure it isn't virus related, and I know it wasn't anyone applying Microsoft updates (I sometimes think I'm the only person who ever downloads them!). It could be RAM, its more likely crappy old PC hard drives and mangled Windows installations choked up with busted DLLs and millions of temp files. I did clear the cache and run autorepair without bringing it back to life, but I suspect whatever has caused the problem is lurking elsewhere.

THE GOOD NEWS
However, I tried substituting and simplifying the code today, and found that the following code DOES work on the affected computers in the top frames:
(Doesn't work: <a href="javascript:history.go(-1)">Back</a>)
DOES work: <a href="javascript:history.back();">Back</a>

I saw something close to the code I ended up with elsewhere on this forum, along with several other variants, none of which worked.
Others which didn't work were:
"javascript:go(-1)" target="main"
onClick="history.back();" (the one I modified)
onClick="parent.history.back(); return false;"

So, the position I now find myself in is not knowing what caused the problem, or whether it will worsen or affect other code, but at least with a fix that works for now. Reading here and elsewhere, it seems a lot of people have inconsistent problems with Frames and Javascript; should I just lie down and accept it as "one of those things"?

Thanks again for your replies.

2:11 am on Sept 5, 2003 (gmt 0)

Preferred Member

10+ Year Member

joined:Nov 19, 2002
posts:372
votes: 0


<a href="javascript:'asdf'">
after clicked it, u get ``asdf'' in browser

function abc() {
return 'abc';
}
<a href="javascript:abc()">
after clicked it, u get ``asd'' in browser

that is, the abc() function is first called, and then, browser "navigate" to the return result of abc();

now:
<a href="javascript:history.go(-1)">
what will this do?
when clicked it, the method "go" of "history" is called, browser is doing a "back", but immediately, browser "navigate" to the return result history.go(-1)
this cancel the "back"

if you're doing:
<a href="javascript:setTimeout('history.go(-1)', 1)">

then u goet a number in browser, cause setTimeout return a number

u can, however, use:
<a href="javascript:void(setTimeout('history.go(-1)', 1))">

but i'll still suggest u use onclick

10:17 am on Sept 5, 2003 (gmt 0)

New User

10+ Year Member

joined:Sept 4, 2003
posts:6
votes: 0


Thanks Xuefer, I think I see where you're going with that explanation.
It also goes some way to explaining a further "feature" of the problem that I just noticed this morning:

When I click the "faulty" code, FOR THE FIRST TIME IN THE SESSION ONLY the mouse pointer turns briefly (maybe for a tenth of a second) into an egg timer then reverts to a pointer again. This indicates that the browser is TRYING to respond to the command history.go(-1), but failing without error. The error state then appears to be "set" as the default condition for that session, as I never get the timer again until I quit and restart.

The "new" version, using history.back() works every time but, as you say, it is only issuing a single command.

Is there a possibility that the frames are interrupting the browser communication with the History list somehow? I was theorising that perhaps the history.go(-1) was explicitly looking for a filename in the History list, whereas the history.back() command was using one in RAM, but not yet written to the list due to - I don't know - some other competing process. I still don't see why this used to work, and then stopped working for no apparent reason.

10:56 am on Sept 5, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Mar 27, 2003
posts:664
votes: 0


Xuefer, it was not the missing quote which threw me. I guessed that was just a typo. What I was saying is that I'm not sure I agree. I understand your logic as described in msg # 7, but I am still not convinced. My understanding is that the browser does not generate a new entry just because it is in the href= part of the tag. I've since tried it on a few browsers and can't reproduce the problem.

Histon, the symptom you describe of seeing the egg timer the first time, then not subsequent times is because the browser has cached the page, not because it is in an error state.

Yes, it could be due to frames. Yousay this all started recently. Did the pages get framed recently? Does the page you came from (that you are going back to) have anything special on it, such as a redirect back to your page?

11:07 am on Sept 5, 2003 (gmt 0)

Preferred Member

10+ Year Member

joined:Nov 19, 2002
posts:372
votes: 0


i never use href="javascritp:...". onclick is my best choise

to ShawnR:
<img src="abigpic.bmp">
<a href="javascript:"></a>
if u click the link while browser(IE) loding that bmp
the img immediately stopped loading, cause it's going to load another page, altuough you may think javascript: is not a navigate

well, it's just all about browser's behavior, don't bother studying it

the onclick will work on all browser with javascript enabled
:)

12:41 pm on Sept 5, 2003 (gmt 0)

New User

10+ Year Member

joined:Sept 4, 2003
posts:6
votes: 0


To Shawn R

- Thanks for looking into it - it's starting to intrigue me now as I understand more of what is happening.
- No, the frames have been present for over a year without exhibiting this behaviour. And no, the page being "backed" to doesn't have anything special, it happens no matter what was the last page loaded, and also all these pages are as "vanilla" as I can make them to try to avoid all this sort of problem! :(

Also, I can see how the page may be cached (therefore avoiding subsequent eggtimers), but if it's cached CORRECTLY, why won't it respond to the history.go(-1), yet will respond to the history.back()? Maybe I'll take up painting instead ;-)

I just wish I could reproduce the behaviour. If I knew how to break it, I'd know how to fix it!

- To Xuefer

I see what you are getting at with the image click being seperate from the javascript command, and how they could interfere with each others progress/ success. I also see how the Time delay could be used to avoid it. I tried 2 onClick variations (see my original reply above) but neither works on the affected pages, although they BOTH work on the affected computers if tried on "flat" pages with no frames present. However, I do use onClick code elsewhere on the pages, and they work there no problem - so it HAS to be some specific problem between the way Frames, the History command and the specific computer setup are interacting.

1:24 pm on Sept 5, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Mar 27, 2003
posts:664
votes: 0


Xuefer, OK, perhaps you are right. Depends on the browser's implementation.

Histon, try cutting stuff from the page until you get to the bare minimum of a page which still produces the problem.

Puzzling thing is that yousay it just started, without any changes...

1:50 pm on Sept 5, 2003 (gmt 0)

Preferred Member

10+ Year Member

joined:Nov 19, 2002
posts:372
votes: 0


to Histon:
<img src="abigpic.bmp">
<a href="javascript:">1st</a>
<a href="http://....a.html">2nd</a>

i meant:
both 1st and 2nd link stop loading imgs, prepairing to load new page
so they're the same.
The ONLY difference is that: "javascript:" will not load a new page.

that's what i was trying to say
but, ok, it's all enough, we're not making browser, we make html pages, let's give this thread an end

and thank u guys give me a chance to review this issue :)

1:55 am on Sept 7, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:July 26, 2003
posts:881
votes: 0


Regardless of whether you put your method / function call in a href or onclick attribute, if it returns a value and you're not returning into a variable, some browsers will interpret the return value as HTML and render it to the client area or to the statusbar or other whacky stuff. I always void() any method / function call that might return a value when I'm not setting a variable (or controlling the event propigation) with it.

Jordan

3:04 am on Sept 7, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Mar 27, 2003
posts:664
votes: 0


"...Regardless of whether you put your method / function call in a href or onclick attribute, if it returns a value and you're not returning into a variable, some browsers will interpret the return value as HTML and render it to the client area ..."

Not sure I understand what you are saying, Jordan. The browser will not render anything on page unless the function is called during page load, or unless the function changes the page content via DOM manipulation. If the function is in the href or the onclick method, then it won't get called during page loading; it will be called when the user follows the link. A slightly allied issue is that it is good habit for the onclick to return a boolean; not void. The boolean should be true if the href part of the a tag should be followed after processing the onclick, and false if processing should stop after processing the onclick. (Or did I misunderstand what you were saying? )

What Xuefer is saying, as I understand it, is that using the href adds a new entry to the history before processing the value of the href addribute (so you return to the same page), whereas using the onclick method does not. I did not think so, but I agree it is possible and is browser dependant.

So, Histon, have you managed to get to a bare minimum of a page which still produces the problem. This will help anyone interested in the problem play with it... It is pretty intriguing since you say it used to work and stopped with no changes made.

3:40 am on Sept 7, 2003 (gmt 0)

Preferred Member

10+ Year Member

joined:Nov 19, 2002
posts:372
votes: 0


no, i never said it's added to history
"javascript:" is just a protocol
same as "http:"

i was just gussing how it work internally, which i'm not sure, this is how i study and remember things.

returning false from onclick will cancel the onclick event
and prevent href to work, thus, no side effect

3:57 am on Sept 7, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:July 26, 2003
posts:881
votes: 0


The browser will not render anything on page unless the function is called during page load, or unless the function changes the page content via DOM manipulation.

Watch what happens when you type this in your URL bar:

javascript: window.open('about:blank','','');

In Firebird 6 (nightly), the returned object handle is printed to the client area as if it were HTML...

"[object Window]"

...and a new blank window opens.

In IE6, same thing, but the handle is anonymous

"[object]"

The reason, as I understand it, is because the return value is interpreted as HTML, or at least as something to do with page display. I've seen one browser, perhaps some flavor of NN4, I don't recall offhand, which would render the returned value as statusbar text while not disturbing the client area.

This is why I always void() method / function calls that may return a value if I don't plan on using the returned value.

If you use href="javascript:someFuncWithAReturn();" then you will (most likely) just end up seeing the return value in the client area:

 <script type="text/javascript">
<!--
function someFuncWithAReturn() {
return "This is a test";
}
//-->
</script>
...
<a href="javascript:someFuncWithAReturn();">Test</a>

...though you could stop from seeing it by wrapping the call in an anonymous function and canceling the propigation of it's execution...

<a href="javascript:function() {someFuncWithAReturn(); return false;}">Test 2</a>

...or, prevent it with the void() method...

<a href="javascript:void(someFuncWithAReturn());">Test</a>

A slightly allied issue is that it is good habit for the onclick to return a boolean; not void. The boolean should be true if the href part of the a tag should be followed after processing the onclick, and false if processing should stop after processing the onclick.

As I understand it, event handler attributes should return void unless one intends to control the way the event is propigated through the Document Object. Bool true means to propigate or bubble the event (depending on the phase), bool false means to cancel propigation.

Jordan

4:30 am on Sept 7, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Mar 27, 2003
posts:664
votes: 0


"...Watch what happens when you type this in your URL bar..."

OK, I understand. You're right. What you are saying is you are not changing the page, you are navigating to a new page.

11:28 am on Sept 9, 2003 (gmt 0)

New User

10+ Year Member

joined:Sept 4, 2003
posts:6
votes: 0


To Shawn R:

I've now simplified the code as much as I can, and uploaded it to a web location so you can have a look; there is also a link so you can download the pages as a unit in zip format.

Link to test files:
<snip>

(Sorry about the length of the link - make sure you have it all on one line!)

Follow the link above, and click on the link to page 1 and then page 2 a couple of times to load the history with some content. Then try going back using the navigation links in the top frame. I find that the .history.back link works in all cases, but the history.go(-1) link only works for an indeterminate time on certain PC/op system/browser combinations before ceasing to work. So far it looks like this is limited to Windows 95/98, IE4 or 5. The problem hasn't appeared on any other combinations. My "captive" PC that displays the problem was upgraded from IE 3 to IE 4, then to IE 5.0, and runs Win 95B. A different client PC which showed the problem was running a new install (freshly formatted disk) of Win 95B and IE 4; the problem disappeared on upgrading to IE 5.5.

[edited by: korkus2000 at 2:39 pm (utc) on Sep. 9, 2003]
[edit reason] No site reviews per TOS [/edit]

1:07 pm on Sept 9, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Mar 27, 2003
posts:664
votes: 0


Hi Histon

A couple of things:

  • I can't test it as I don't have those versions of Windows
  • Please be aware of the terms of use of WebmasterWorld. You can't post any personal urls, so you should edit your post to remove it. What I meant was for you to post the actual code if small enough, not the url. Also, minimising the code to the bare minimum which produces the bug might help you debug it. e.g. Does it still occur if not framed?
  • I note you are still using the construct <a href="javascript:history.go(-1)"> rather than something like <a href="#" onclick="javascript:history.go(-1); return false;"> per the various discssions above. It is an intriguing problem because it just started for no apparent reason, but still... some problems aren't worth spending too much time on if you have found a viable work-around, especially if you are just talking about very old operating systems running old browsers. So if the suggestions by Xuefer fix it (or if history.back fixes it) why not just use one of those?

Sorry I can't be more help...

Shawn

5:24 pm on Sept 9, 2003 (gmt 0)

New User

10+ Year Member

joined:Sept 4, 2003
posts:6
votes: 0


Okay, sorry. The URL has already been removed by the moderator, it wasn't what I would consider a personal URL, just a link to the problem code. My bad, won't happen again.

It's difficult to post the actual code, since it involves 3 frames, a frameset for them to sit in and 2 web pages for content to navigate back and forth. It's still less than 2kb zipped, but too much code to fill a message board with.

When I place the history.go(-1) in the centre frame, it works fine; it's a frame-specific problem. This doesn't help me, as the site requires the code to be in the top frame.

As I said in message 11, I tried the onClick routines, but they don't work either on the affected PCs (although they do work out of frames on the affected PCs!)

I'm happy to use the history.back() code, since it works, but since that was also the case with the history.go(-10 code until last week, I'd really like to know why it stopped working! As for old operating systems and browsers, sadly my customers USE old PCs, operating systems and browsers so I can't afford to ignore the problem. I'll keep working on it.

Thanks a lot for all your help though, guys - it's really helped me get my head around the possible causes of the problem, and it did sort of lead to the answer. ;-)

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members