javascript window.history.go(-1) 在 iOS HomeScreen 应用程序中不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21625126/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 21:20:15  来源:igfitidea点击:

window.history.go(-1) not working in iOS HomeScreen App

javascriptjqueryiosweb-applications

提问by Nict

So I'm trying to redirect the user back one level in the history on an iPhone HomeScreen App, but it's simply just not firing for some reason.

所以我试图将用户重定向回 iPhone HomeScreen 应用程序历史记录中的一个级别,但它只是出于某种原因没有触发。

Current code is as follows window.history.go(-1)

当前代码如下 window.history.go(-1)

I've also tried various other version window.history.back(), history.go(-1), but no luck yet. I can't wrap my head around how to implement the pushState, so I haven't tried that approach yet, but it's quite annoying how incredibly bad the homescreen app stuff is made.

我也尝试过各种其他版本window.history.back()history.go(-1)但没有运气呢。我无法理解如何实现 pushState,所以我还没有尝试过这种方法,但令人讨厌的是主屏幕应用程序的东西制作得非常糟糕。

Atleast you're able to debug with Safari.

至少您可以使用 Safari 进行调试。

回答by Chris Gunawardena

You can debug mobile safari, but unfortunately you need a mac.

您可以调试移动 safari,但不幸的是您需要一台 mac。

If not, try this:

如果没有,试试这个:

  1. Make sure your code is working and no errors on desktop safari;
  2. Check if you are actually making the call by adding an alert("history() called")in place of the history(-1)code;
  3. Is it in a link that has a default behavour to navigate to another page? If so, you need a event.preventDefault()or at least a return false;after the history() call.
  1. 确保您的代码在桌面 safari 上正常工作并且没有错误;
  2. 通过添加alert("history() called")代替history(-1)代码来检查您是否确实在进行调用;
  3. 它是否位于具有导航到另一个页面的默认行为的链接中?如果是这样,则在 history() 调用之后需要一个event.preventDefault()或至少一个return false;

iOS simulator safari debugger

iOS 模拟器 safari 调试器

回答by Samuel Williams

Try something like:

尝试类似:

<a href="javascript:history.go(-1)">Go back</a>