我有一个 WKWebView,它加载了一个名为“start.html”的本地 html 文件。 在这个文件中,我在 iframe 中加载了另一个本地文档。
但我不允许在 iframe 内容上使用 start.html 中的 js,并且 iframe 内容不允许加载 js 文件。
在 WKWebView 之前我使用 UIWebView 但我被迫迁移以提高性能
在 UIWebView 中,我从未遇到过任何跨域安全问题。
当我在 iframe 上添加属性 sandbox='allow-same-origin'
时,我可以像这样从 start.html 成功执行 js 代码
$("#frame")[0].contentWindow.document.getElementsByClassName('password_field')[0].value = password_field
但是 iframe 中的 js 代码和 http 请求(iframe 中加载的文件是 js 播放器)不允许运行,我得到这些错误:
Blocked a frame with origin "null" from accessing a frame with origin "null". Protocols, domains, and ports must match.
UIWebVIew 和WKWebView 有什么区别。 是否有允许 iframe 内的 js 代码和 http 请求的解决方案?
最佳答案
WKWebView
只允许读取存储在 NSTemporaryDirectory()
提供的目录中的本地内容。
请看我的回答here了解更多详情。
关于javascript - iframe 中的 WKWebView 本地文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35718588/