Bug Tracker

Opened 7 years ago

Closed 7 years ago

#14184 closed bug (notabug)

.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

Change History (2)

comment:1 Changed 7 years ago by anonymous

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

comment:2 Changed 7 years ago by dmethvin

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.

Note: See TracTickets for help on using tickets.