gpt4 book ai didi

ios - 为什么我的 html 没有加载到我的 WKWebView

转载 作者:行者123 更新时间:2023-11-28 14:25:53 25 4
gpt4 key购买 nike

我正在尝试将嵌入的 html 和 javascript 呈现到我的 WKWebView 中。这将是一个使用 tradingview.com 显示股票图表的 View 。

我得到的只是一个空白的 WebView 。

@IBOutlet weak var wbTradingView: WKWebView!

override func viewDidLoad() {
super.viewDidLoad()
let embedCode = "<html><body><!-- TradingView Widget BEGIN --><div class='tradingview-widget-container\"><div id=\"tradingview_70a8b\"></div><div class=\"tradingview-widget-copyright\"><a href=\"https://www.tradingview.com/symbols/NASDAQ-FB/\" rel=\"noopener\" target=\"_blank\"><span class=\"blue-text\">FB chart</span></a> by TradingView</div><script type=\"text/javascript\" src=\"https://s3.tradingview.com/tv.js\"></script><script type=\"text/javascript\">new TradingView.widget({\"autosize\": true,\"symbol\": \"NASDAQ:FB\",\"interval\": \"D\",\"timezone\": \"Etc/UTC\",\"theme\": \"Dark\",\"style\": \"2\",\"locale\": \"en\",\"toolbar_bg\": \"#f1f3f6\",\"enable_publishing\": false,\"hide_top_toolbar\": true, \"hide_legend\": true,\"save_image\": false,\"container_id\": \"tradingview_70a8b\"});</script></div><!-- TradingView Widget END --></body></html>"

wbTradingView.translatesAutoresizingMaskIntoConstraints = false
wbTradingView.loadHTMLString(embedCode, baseURL: nil)


}

解决方法:

override func viewDidLoad() {
super.viewDidLoad()
let embedCode = """
<html>
<body>
<div class="tradingview-widget-container">
<div id="tradingview_70a8b"></div>
<div class="tradingview-widget-copyright"><a href="https://www.tradingview.com/symbols/NASDAQ-FB/" rel="noopener" target="_blank"><span class="blue-text">FB chart</span></a> by TradingView</div>
<script type="text/javascript" src="https://s3.tradingview.com/tv.js"></script>
<script type="text/javascript">
new TradingView.widget(
{
"autosize": true,
"symbol": "NASDAQ:FB",
"interval": "D",
"timezone": "Etc/UTC",
"theme": "Dark",
"style": "2",
"locale": "en",
"toolbar_bg": "#f1f3f6",
"enable_publishing": false,
"hide_top_toolbar": true,
"hide_legend": true,
"save_image": false,
"container_id": "tradingview_70a8b"
}
);
</script>
</div>
</body>
</html>
"""

wbTradingView.translatesAutoresizingMaskIntoConstraints = false
wbTradingView.loadHTMLString(embedCode, baseURL: nil)


}

最佳答案

通过使用这个

https://validator.w3.org/check

您的html无效,您可以通过设置来验证

let embedCode  = """
<html>
<body bgcolor="#E6E6FA">
<h1>Hello world!</h1>
<p><a href="https://www.w3schools.com">Visit W3Schools.com!</a></p>
</body>
</html>
"""

关于ios - 为什么我的 html 没有加载到我的 WKWebView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51573132/

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