WKWebView在html中打开src

时间:2018-12-19 12:29:51

标签: ios wkwebview

您好,我正在尝试将带有以下元素的html加载到WKWebView:

<iframe align=\"middle\"
 allowtransparency=\"\"
 frameborder=\"0\"
 height=\"820px\"
 id=\"\"
 scrolling=\"no\"
 seamless=\"\"
 src=\"//my.site.ru/files_static/edd/2016/speech_countries/6/first.html\" 
 width=\"100%\">
</iframe>

WKWebView无法加载内容,而是显示一个空白屏幕。但是,如果我将https或http添加到src,则该元素将成功加载:

<iframe align=\"middle\"
 allowtransparency=\"\"
 frameborder=\"0\"
 height=\"820px\"
 id=\"\"
 scrolling=\"no\"
 seamless=\"\"
 src=\"http://my.site.ru/files_static/edd/2016/speech_countries/6/first.html\" 
 width=\"100%\">
</iframe>

我搜索了一些属性来为WKWebView,WKPreferences,WKWebViewConfiguration中的WKWebView设置默认协议,但没有找到任何东西。 WKWebview可以在没有协议的情况下通过链接加载html吗?

找到答案:调用loadHtmlString时需要设置baseUrl字符串

1 个答案:

答案 0 :(得分:1)

您可以使HTML内容相对于“基本”网址...

我假设您正在使用.loadHTMLString(...)

如果是这样,请将您的src=更改为:

src=\"/files_static/edd/2016/speech_countries/6/first.html\"

并将您的.loadHTMLString()更改为:

theWebView.loadHTMLString(htmlString, baseURL: URL(string: "http://my.site.ru"))

https://my.site.ru

相关问题