gpt4 book ai didi

ios - WKWebView在html中打开src

转载 作者:行者123 更新时间:2023-11-28 23:39:48 26 4
gpt4 key购买 nike

您好,我正在尝试将具有以下元素的 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 设置默认协议(protocol),但没有找到任何东西。WKWebview可以不通过协议(protocol)通过链接加载html吗?

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

最佳答案

您可以使 html 内容相对于“基本”url...

我假设您正在使用 .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

关于ios - WKWebView在html中打开src,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53851300/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com