iframe中的WKWebView本地文件

Kho*_*win 5 javascript objective-c cross-domain ios wkwebview

我有一个WKWebView,它加载了一个名为'start.html'的本地html文件.在此文件中,我在iframe中加载了其他本地文档.

但我不允许在iframe内容上使用来自start.html的js,并且不允许iframe内容加载js文件.

在WKWebView之前我使用UIWebView但我不得不迁移以提高性能

在UIWebView中,我从未遇到过跨域安全性的任何问题.

当我sandbox='allow-same-origin'在iframe上添加属性时,我可以像这样从start.html成功执行js代码

$("#frame")[0].contentWindow.document.getElementsByClassName('password_field')[0].value = password_field
Run Code Online (Sandbox Code Playgroud)

但是ifs内部的js代码和http请求(在iframe中加载的文件是一个js播放器)是不允许运行的,我得到了这些错误:

Blocked a frame with origin "null" from accessing a frame with origin "null". Protocols, domains, and ports must match.
Run Code Online (Sandbox Code Playgroud)

UIWebVIew和WKWebView有什么区别.是否有解决方案允许在iframe中使用js代码和http请求?

Tho*_*iot 1

WKWebView只允许读取存储在 提供的目录中的本地内容NSTemporaryDirectory()

请参阅我的回答了解更多详细信息。