[英]HTML5 History API: Refresh and Back issues
I'm writing code to create a UX similar to how photos are viewed on Facebook from the timeline... 我正在编写代码来创建一个类似于从时间轴上在Facebook上查看照片的用户体验......
I have most of this working via the HTML5 History API .
我通过HTML5 History API完成了大部分工作。 Here is what I'm doing when clicking an image...
这是我点击图片时正在做的...
preventDefault()
to avoid following the link (to the image page) and instead AJAX load a modal with the image preventDefault()
来避免跟随链接(到图像页面)而不是AJAX加载模式与图像 pushState
the URI of the image page so it appears in the address bar pushState
图像页面的URI,使其出现在地址栏中 Question: At step #4, is there a way to bypass the history API and just have the browser perform a standard "Back" action so I can return to the previous page (ie the timeline)?
问题:在步骤#4,有没有办法绕过历史API,只是让浏览器执行标准的“后退”操作,这样我就可以返回上一页(即时间轴)?
Have you tried a good ol' fashioned history.go(-1);
你有没有尝试过很好的
history.go(-1);
? ?
I do it like this: 我是这样做的:
step 1 - save the initial page url (which is yet unchanged) 第1步 - 保存初始页面网址(尚未更改)
var savedPageStateURL = window.location.pathname;
step 2 - replace current history state ( not pushing, only replacing) 第2步 - 替换当前历史状态( 不推,只替换)
window.history.replaceState( {}, null , url );
step 3 - revert history changes and go back to the first step's state 第3步 - 恢复历史记录更改并返回第一步的状态
if( 'pushState' in window.history && window.history.state )
window.history.replaceState( {}, null , savedPageStateURL );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.