popstate返回event.state未定义 [英] popstate returns event.state is undefined
问题描述
我在本示例中了解HTML5中的历史记录(打开JavaScript浏览器控制台以查看错误) event.state.url
返回:
未捕获TypeError:无法读取未定义
的财产'url'
查看和帮助: http://jsfiddle.net/un4Xk/
要访问DOM事件对象,请使用 event.originalEvent
: http://jsfiddle.net/pimvdb/un4Xk/1/ 。
var state = event.originalEvent.state;
请记住,状态仅在新状态包含数据时定义,因此在单击时不可用然后回到初始状态:
- 初始状态
- 链接到状态1
- 返回按钮至初始状态(无可用数据)
然而,点击,点击另一个时间然后返回:
- 初始状态
- 链接到状态1
- 链接至状态2
- 后退按钮至状态1(可用数据)
I am learning about history in HTML5, in this example (open the JavaScript browser console to see error) the event.state.url
returns:
Uncaught TypeError: Cannot read property 'url' of undefined
Look and help: http://jsfiddle.net/un4Xk/
event
is the jQuery event object, not the DOM one.
To access the DOM event object, use event.originalEvent
: http://jsfiddle.net/pimvdb/un4Xk/1/.
var state = event.originalEvent.state;
Remember that the state is only defined when the new state has data, so it is not available when clicking and then going back to the initial state:
- initial state
- link to state 1
- back button to initial state (no data available)
It is, however, available when clicking, clicking another time and then going back:
- initial state
- link to state 1
- link to state 2
- back button to state 1 (data available)
这篇关于popstate返回event.state未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!