开发者

Opera back-button cache functionality

开发者 https://www.devze.com 2023-04-11 19:25 出处:网络
I have some jQuery which modifies elements on the page after the user performs 开发者_开发问答an action.These are persisted server-side so it all looks nice and fluid for the user.

I have some jQuery which modifies elements on the page after the user performs 开发者_开发问答an action. These are persisted server-side so it all looks nice and fluid for the user.

When the user clicks off-site and then hits the back button all browsers except Opera re-request the page, hence the changes still appear for the user. With Opera however the site returns to it's pre-Jquery state (since it didn't request the page from the server).

I could do something nasty like check the browser and refresh if Opera, but obviously this is not ideal.

Any ideas of a better method to solve this?


Could you perhaps use some HTML5 local storage to persist these changes client side (for those users that have HTML5 compliant browsers) and gracefully degrade to server requests for those that don't.

After a quick scoot around - It appears that Opera started supporting LocalStorage in Opera 10.5 (back in early 2010), I think it also auto-updates too, so most of the 2.7% of users using Opera should have this functionality.

I'd suggest using http://www.modernizr.com/ to check for the presence of functionality and then perhaps store the results in a Object Literal JSON the results of that into Local Storage (should make storage and retrieval easier!)

(HTML5 Local Storage guide - http://php-html.net/tutorials/html5-local-storage-guide/)


Not one to answer my own question but it appears the following solves my problem:

history.navigationMode = 'fast';

Setting this means that pages will be loaded in the exact state that they were in when you left the page, which is basically what I was looking for. It appears to be an Opera only setting, although it appears to be only Opera which acts differently.

I found the information here.


Opera has some heuristics to determine whether a page needs a "re-init" on history navigation. Heuristics include whether the page is listening for the unload event (because we can't "undo" whatever the unload event did), and whether the code that cause navigation ran from a click event (because scripts often disable buttons and make not easily reversible changes to the page's state). If you can avoid triggering the heuristics (Keep It Simple), the problem should go away even without the history.navigationMode hack.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号