Why window.history.go() doesn't work from some pages?

0

(edit: changed most of the question)

I got my answer regarding How to go to the very first page of a tab.

Basically a bookmarklet

  javascript:window.history.go(-(window.history.length - 1))

It works well from all pages, but from some pages, especially the ones that were idle for a long time, it doesn't.

Is there a better way to use that bookmarklet?

Ring Ø

Posted 2010-12-01T16:31:06.267

Reputation: 483

I'm not using either, but: what does javascript:alert(window.history.length) give you? (Just copy & paste into the location/address bar, of the window that has iGoogle loaded.) – Arjan – 2010-12-01T16:47:51.520

It gives me the correct number (was 19 for Google news, which does a refresh via href=... [see above]). Tried to check window.onunload and body.onunload they're all undefined. – Ring Ø – 2010-12-01T16:49:52.817

Maybe lower the number a bit, like javascript:window.history.go(-5) to see what happens? – Arjan – 2010-12-01T16:51:55.980

And: any errors when you open the Javascript console? (Just type javascript: to open that -- though that fails on my FF4 beta now.) – Arjan – 2010-12-01T16:54:54.063

No error in Firebug. This is really strange... – Ring Ø – 2010-12-20T23:18:26.113

@ring0: Can you give an example of a such a page? – harrymc – 2010-12-27T18:42:50.063

Answers

0

I would try adding some form of validation on the value you are passing. Also: you say it doesn't work but you don't say how it doesn't work (e.g. "it refreshes the current page"; or "it goes back to 1st page plus 1")

Cribbed from w3:

The go(delta) method causes the UA to run the following steps:

   1. If the argument to the method was omitted or has the value zero, then act as if the location.reload() method was called instead, and abort these steps.
   2. Let delta be the argument to the method.
   3. If the index of the current entry of the joint session history plus delta is less than zero or greater than or equal to the number of items in the joint session history, then the user agent must do nothing.
   4. Let specified entry be the entry in the joint session history whose index is the sum of delta and the index of the current entry of the joint session history.
   5. Let specified browsing context be the browsing context of the specified entry.
   6. Traverse the history of the specified browsing context to the specified entry.

horatio

Posted 2010-12-01T16:31:06.267

Reputation: 1

"It doesn't work" means that the browser tab doesn't move at all. The bookmarklet has not effect. Changing the go(x) with x==-1 doesn't have any effect either - while the history.length is 10. Maybe a Firefox pb... – Ring Ø – 2010-12-30T16:56:35.603