This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 17811 - Expose history traversal direction
Summary: Expose history traversal direction
Status: RESOLVED WORKSFORME
Alias: None
Product: WHATWG
Classification: Unclassified
Component: HTML (show other bugs)
Version: unspecified
Hardware: Other other
: P3 normal
Target Milestone: Unsorted
Assignee: Ian 'Hixie' Hickson
QA Contact: contributor
URL: http://www.whatwg.org/specs/web-apps/...
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-07-18 06:53 UTC by contributor
Modified: 2012-12-07 22:49 UTC (History)
5 users (show)

See Also:


Attachments

Description contributor 2012-07-18 06:53:25 UTC
This was was cloned from bug 15366 as part of operation convergence.
Originally filed: 2011-12-30 11:21:00 +0000
Original reporter: Anne <annevk@annevk.nl>

================================================================================
 #0   Anne                                            2011-12-30 11:21:40 +0000 
--------------------------------------------------------------------------------
E.g. for CSS transitions it would be nice if history traversal direction was known. Especially now there's history.pushState(). You can track this yourself but it would be nicer if it was explicitly exposed.

(Feedback from Ben Joffe.)
================================================================================
 #1   Ben Joffe                                       2011-12-30 11:35:00 +0000 
--------------------------------------------------------------------------------
Perhaps this could be a property of the event object as an integer (defined the same as the argument that could have been passed to history.go to trigger the navigation).

Another reason to want this property: some navigational states may be associated with an xhr request, if the navigation is back then it may be appropriate to display the previous result of that request, but if it is forward it may be appropriate to redo the request.
================================================================================
 #2   Ian 'Hixie' Hickson                             2012-02-01 00:54:32 +0000 
--------------------------------------------------------------------------------
Interesting idea.

Sometimes the direction is forward relative to the last state that was active in the document, but backward relative to the last active entry in the session history, what would you do for that?
================================================================================
Comment 1 Ian 'Hixie' Hickson 2012-09-16 03:56:05 UTC
Ben, any feedback on the question in #2 above?
Comment 2 Ian 'Hixie' Hickson 2012-09-18 23:03:59 UTC
Anne, without further info from Ben regarding what he wants, I don't know what to do here.
Comment 3 Ben Joffe 2012-09-27 12:27:39 UTC
Hixie: I can't see the scenario that would lead to what you describe in #2, from what I understand the document history delta should always be the same as the browser history delta. Could you please elaborate?
Comment 4 Ian 'Hixie' Hickson 2012-09-28 03:41:39 UTC
Ben: Yeah. Consider this case:

 1. User opens a.html.
 2. User clicks a link to b.html.
 3. User clicks a link to b.html#z.
 4. User goes back in one step to a.html, by using the drop-down next to the back button.
 5. User clicks the forward button.

Now b.html gets a forward navigation to its first session history entry, but the last active state of that document was its second session history entry.
Comment 5 Ben Joffe 2012-09-28 09:21:00 UTC
Ah I see, thanks.
In that case I guess the value could potentially be defined in two different ways, though I think being defined relative to the document's last history state has several advantages:

- If the document relies on this property for animations then it will animate in the correct direction for whatever content is flashed on the page to start with.
- Compatibility libraries can provide this property for older browsers, whereas if it's relative to the browser there won't be a way to detect the actual delta.
- In your example on step 4, a.html doesn't need to do any history management, no popstate is fired currently (if I understand correctly), which matches the behaviour of a delta of zero not firing a popstate if this is relative to the document.
Comment 6 Arthur Stolyar 2012-12-04 12:17:26 UTC
Hello. I read this conversation and have some opinions about this situation. 

May be need just define new attribute of History interface, which indicates the current index of history traversal. For example you can define |currentIndex| attribute which is change right before popstate/hashchange event is fired. So, developer can store previous index of history traversal and compare difference with new |currentIndex| and last |currentIndex|.

Sorry if I have mistakes in my text. I am not native speaker.
Comment 7 Ian 'Hixie' Hickson 2012-12-07 22:49:05 UTC
If you just want to animate from the current state to the new state, it seems that there's no need to use a new feature on History. You already know what state you're currently in, basically by definition. You know what state you're going to. Just animate between them.

So I don't understand what this would add.

If I'm missing something, please don't hesitate to reopen the bug.