使用 WKWebView 时 localStorage 不保存在 iFrame 中
localStorage not saving inside iFrame when using WKWebView
在 WKWebView 中使用时,我为这个 iFrame 问题抓狂,因为 localStorage 的 none 更改仍然存在。虽然这些值似乎是在应用程序仍在 运行 时保存的,但一旦应用程序终止,iFrame 页面中的所有 localStorage 值都会被清除。
所以这是我的标准网页视图代码
override func viewDidLoad() {
super.viewDidLoad()
guard let url = URL(string: "https://example.com") else {
return
}
webView.configuration.preferences.javaScriptEnabled = true
view.addSubview(webView)
webView.load(URLRequest(url: url))
}
https://example.com returns a page that contains an iFrame which references a sub page within https://example.com.
我已经尝试在 iFrame 标记中添加 sandbox="allow-same-origin" 但无济于事。
可以使用一些关于如何使它工作的想法。提前致谢。
通过使父框架和子框架来自同一域来解决问题。
例如:如果页面在 https://mysite.example.com, the iFrame can't be to https://exmaple.com/mypage.html 加载,这正是我看到问题时的设置。
在 WKWebView 中使用时,我为这个 iFrame 问题抓狂,因为 localStorage 的 none 更改仍然存在。虽然这些值似乎是在应用程序仍在 运行 时保存的,但一旦应用程序终止,iFrame 页面中的所有 localStorage 值都会被清除。
所以这是我的标准网页视图代码
override func viewDidLoad() {
super.viewDidLoad()
guard let url = URL(string: "https://example.com") else {
return
}
webView.configuration.preferences.javaScriptEnabled = true
view.addSubview(webView)
webView.load(URLRequest(url: url))
}
https://example.com returns a page that contains an iFrame which references a sub page within https://example.com.
我已经尝试在 iFrame 标记中添加 sandbox="allow-same-origin" 但无济于事。
可以使用一些关于如何使它工作的想法。提前致谢。
通过使父框架和子框架来自同一域来解决问题。
例如:如果页面在 https://mysite.example.com, the iFrame can't be to https://exmaple.com/mypage.html 加载,这正是我看到问题时的设置。