【发布时间】:2019-11-08 09:51:16
【问题描述】:
我目前正在使用 HTML 文件加载 Web 视图。网络功能在js 文件中处理。这不是问题。
但我的问题是返回按钮。我检查是否有要返回的页面。所以我们使用document.referrer 来显示使用现有服务器的网络视图。
但它不起作用,因为它在创建 iOS hybridApp 时在 iOS 内部使用。
所以我检查了history.back() 是否有效。有用。有一个页面可以返回。
有页面需要退回,但是document.referrer不行。
在html包含js文件中从主页移动到详细页面
location.href = './Detail.html'
Common.js文件头中的后退按钮功能
alert(document.referrer) // return empty
if (document.referrer) {
history.back();
} else {
location.href = "./Main.html"; // only can do
}
两个 html 文件(Main,Detail) 使用一个共同的标题。该函数位于Common.js 文件中。我正在使用 Swift5
Main.html
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0,minimum-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover, shrink-to-fit=no">
<meta name="referrer" content="always">
Detail.html
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0,minimum-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover, shrink-to-fit=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="referrer" content="always">
我们如何解决这个问题?
提前致谢。
【问题讨论】:
-
这能回答你的问题吗? document.referrer exists but is always empty
-
@MosèRaguzzini 这似乎是一个 object-C 解决方案,我正在使用 Swift5。所以很难理解一个解决方案。
-
这是与 IOS webview 交互的 javascript,伙计。不管包装器是什么。
-
@MosèRaguzzini 你链接到我的答案有一个链接到它手动设置的标题方法。但答案是对象-C 代码。
-
@MosèRaguzzini 我从您的链接答案中知道为什么它不起作用,但我不知道根本的解决方案。
标签: javascript html ios swift