【问题标题】:WKWebView open src in htmlWKWebView 在 html 中打开 src
【发布时间】:2018-12-19 12:29:50
【问题描述】:

您好,我正在尝试将带有以下元素的 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 无法加载内容,而是显示一个空白屏幕。但是如果我在 src 中添加 https 或 http,则元素加载成功:

<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字符串

【问题讨论】:

标签: ios wkwebview


【解决方案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

【讨论】:

    猜你喜欢
    • 2019-10-24
    • 2020-04-19
    • 2015-08-16
    • 1970-01-01
    • 1970-01-01
    • 2020-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多