Skip to main content

Bug Tracker

Side navigation

#14184 closed bug (notabug)

Opened July 25, 2013 04:09PM UTC

Closed July 25, 2013 08:35PM UTC

.on('popstate', function(e){}) does not pick up e.state data

Reported by: anonymous Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.10.2
Keywords: Cc:
Blocked by: Blocking:
Description

implementing ajax history:

$('a').click(function(e){
    e.preventDefault();
    var d = this.href;
    window.history.pushState({data: d}, d, d);
    $('#state').text(d);
});

when using:

window.onpopstate = function(e){
	var d = e.state || {data: 'no state'};
	$('#state').text(d.data);
};

http://jsfiddle.net/jBHgU/

the history can pop up the pushed state.

but when using:

$(window).on('popstate', function(e){
	var d = e.state || {data: 'no state'};
	$('#state').text(d.data);
});

http://jsfiddle.net/hQTTX/1/

the pushed state can not be popped up, although the event is triggered

Attachments (0)
Change History (2)

Changed July 25, 2013 04:34PM UTC by anonymous comment:1

tested on chrome Version 28.0.1500.72 m and firefox 22

implementing ajax history:

$('a').click(function(e){
    e.preventDefault();
    var d = this.href;
    window.history.pushState({data: d}, d, d);
    $('#state').text(d);
});

when using:

window.onpopstate = function(e){
	var d = e.state || {data: 'no state'};
	$('#state').text(d.data);
};

http://jsfiddle.net/jBHgU/

the history can pop up the pushed state. but when using:

$(window).on('popstate', function(e){
	var d = e.state || {data: 'no state'};
	$('#state').text(d.data);
});

http://jsfiddle.net/hQTTX/1/

the pushed state can not be popped up, although the event is triggered

Changed July 25, 2013 08:35PM UTC by dmethvin comment:2

resolution: → notabug
status: newclosed

http://api.jquery.com/category/events/event-object/

Certain events may have properties specific to them. Those can be accessed as properties of the event.originalEvent object.