返回iPhone时刷新网页状态[重复]

时间:2022-08-24 09:20:02

This question already has an answer here:

这个问题在这里已有答案:

On iPhone (at least ios8), if we animate stuff as the user is leaving the page (for example he clicked a link), when the user press the "back button", he come to the page and the previous state or the webpage with the style property changed by animation stay there.

在iPhone(至少ios8)上,如果我们在用户离开页面时动画内容(例如他点击链接),当用户按下“后退按钮”时,他会进入页面和之前的状态或网页由动画改变的样式属性留在那里。

It looks like Safari doesn't reload the page, but cache the DOM state and just rerender it or something.

看起来Safari不会重新加载页面,而是缓存DOM状态并只是重新呈现它。

Anyone know workaround this behavior? Or have links to relevant documentation describing the behavior?

有人知道解决这个问题吗?或者链接到描述行为的相关文档?

2 个解决方案

#1


0  

You can try a crude js 1 second setinterval? set a datetime variable, and next interval check if the existing variable is 1 second ago.

你可以尝试粗略的js 1秒设置间隔?设置一个datetime变量,然后检查现有变量是否是1秒前的下一个间隔。

if not means the user has navigated to other page.

如果不是意味着用户已导航到其他页面。

#2


0  

The behavior is related to Safari's Back/Forward cache. You can learn about it on the relevant Apple documentation: http://web.archive.org/web/20070612072521/http://developer.apple.com/internet/safari/faq.html#anchor5

该行为与Safari的后退/转发缓存有关。您可以在相关的Apple文档中了解它:http://web.archive.org/web/20070612072521/http://developer.apple.com/internet/safari/faq.html#anchor5

Apple's own fix suggestion is to add an empty iframe on your page:

Apple自己的修复建议是在页面上添加一个空的iframe:

<iframe style="height:0px;width:0px;visibility:hidden" src="about:blank">
    this frame prevents back forward cache
</iframe>

This question also have been answered here: Prevent safari loading from cache when back button is clicked (he solution proposed there diverge from the Apple documentation)

这里也回答了这个问题:单击后退按钮时防止从缓存中加载safari(他提出的解决方案与Apple文档不同)

#1


0  

You can try a crude js 1 second setinterval? set a datetime variable, and next interval check if the existing variable is 1 second ago.

你可以尝试粗略的js 1秒设置间隔?设置一个datetime变量,然后检查现有变量是否是1秒前的下一个间隔。

if not means the user has navigated to other page.

如果不是意味着用户已导航到其他页面。

#2


0  

The behavior is related to Safari's Back/Forward cache. You can learn about it on the relevant Apple documentation: http://web.archive.org/web/20070612072521/http://developer.apple.com/internet/safari/faq.html#anchor5

该行为与Safari的后退/转发缓存有关。您可以在相关的Apple文档中了解它:http://web.archive.org/web/20070612072521/http://developer.apple.com/internet/safari/faq.html#anchor5

Apple's own fix suggestion is to add an empty iframe on your page:

Apple自己的修复建议是在页面上添加一个空的iframe:

<iframe style="height:0px;width:0px;visibility:hidden" src="about:blank">
    this frame prevents back forward cache
</iframe>

This question also have been answered here: Prevent safari loading from cache when back button is clicked (he solution proposed there diverge from the Apple documentation)

这里也回答了这个问题:单击后退按钮时防止从缓存中加载safari(他提出的解决方案与Apple文档不同)