我如何“伪造”客户端应用页面的Windows状态更改(角度)? [英] How do I "fake" a windows statechange for a client-side app page (angular)?
问题描述
这个问题不紧急,但我很好奇
问题
我正在编写一个大量使用jquery,signalr和angularjs的应用程序。该应用程序存在于一个页面中,因此用户无需等待页面加载。
此应用程序的用户群非常小。
因为所有事情都发生在单个页面中,导航历史记录将不会更新,这意味着如果用户因习惯而点击后退按钮,他们就会有效退出应用程序。
想法和限制
我不想禁用后退按钮,因为用户可能需要向后导航(虽然我已经考虑过禁用卸载,除非用户点击退出按钮或同意确认退出模式,但这些可能非常烦人)。
理想情况下,我想劫持后退操作,以便我可以通过应用程序上的步骤导航用户。我可以通过保持应用页面操作的堆栈(像历史记录)来做到这一点。但是,如果我这样做,那么我将不得不包括向前导航的选项,这将意味着高举浏览器历史记录,因此它会认为有一个页面要转发。我不知道怎么做:S
基本上我的问题是:
我怎么能在我的单页应用程序中最好的处理导航是最直观的(使用浏览器导航按钮)和最不烦人(避免禁用浏览器导航按钮)
谢谢^ _ ^
Andy
听起来你正在寻找历史API,特别是pushState
方法和popstate
事件:
操纵浏览器历史记录 [ ^ ]
浏览器支持非常好:
http://caniuse.com/#feat=history [ ^ ]
对于旧版浏览器,GitHub上有一个polyfill:
https://github.com/browserstate /history.js/ [ ^ ]
Hi,
This issue isn't urgent, but I am curious
The problem
I am writing an app that heavily uses jquery, signalr and angularjs. The app exists in a single page so the user doesn't have to wait for page loads.
There is a very small user base for this app.
Because everything happens within the single page, the navigation history will not be updated, meaning that if a user hits the "back" button out of habit, they effectively exit the app.
Ideas and restrictions
I don't want to disable the back button as the user may need to navigate back (although I have considered disabling unload unless the user clicks an "exit" button or agrees to a "confirm exit" modal, but these can be VERY annoying).
Ideally I would like to hijack the "back" operation so I can navigate the user back through steps on the application. I could do that by keeping a stack ("like history") of the app page actions. However, if I do that then I would have to include the option to navigate forward, and that would mean high-jacking the browser history so it would think there is a page to forward to. I have no idea how to do that :S
So basically my question is:
How can I best handle navigation in my single-page app that is the most intuitive (using browser nav buttons) and the least annoying (avoiding disabling the browser nav buttons)
Thanks ^_^
Andy
Sounds like you're looking for the History API, particularly thepushState
method and thepopstate
event:
Manipulating the browser history[^]
Browser support is pretty good:
http://caniuse.com/#feat=history[^]
For older browsers, there's a polyfill on GitHub:
https://github.com/browserstate/history.js/[^]
这篇关于我如何“伪造”客户端应用页面的Windows状态更改(角度)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!