我有一个WKWebView,它加载了一个名为'start.html‘的本地html文件。在这个文件中,我在iframe中加载了另一个本地文档。
但是我不允许在iframe内容上使用来自start.html的js,并且不允许加载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请求?
发布于 2017-09-25 07:53:00
仅允许WKWebView
读取存储在NSTemporaryDirectory()
提供的目录中的本地内容。
有关详细信息,请参阅我的答案here。
https://stackoverflow.com/questions/35718588
复制相似问题