gpt4 book ai didi

javascript - 在 UIWebView 上加载 javascript

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

我有一个javascript,只是想将其加载到我的UIWebView上,无法弄清楚我做错了什么。这是我的脚本:

<script type='text/javascript'>(function () { var done = false; var script = document.createElement('script'); script.async = true; script.type = 'text/javascript'; script.src = 'https://app.purechat.com/VisitorWidget/WidgetScript'; document.getElementsByTagName('HEAD').item(0).appendChild(script); script.onreadystatechange = script.onload = function (e) { if (!done && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) { var w = new PCWidget({ c: 'ea5935c8-1f44-4172-bcd7-18d6f316ad75', f: true }); done = true; } }; })();</script>

这是我的代码:

NSString *temp =@"<script type='text/javascript'>(function () { var done = false; var script = document.createElement('script'); script.async = true; script.type = 'text/javascript'; script.src = 'https://app.purechat.com/VisitorWidget/WidgetScript'; document.getElementsByTagName('HEAD').item(0).appendChild(script); script.onreadystatechange = script.onload = function (e) { if (!done && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) { var w = new PCWidget({ c: 'ea5935c8-1f44-4172-bcd7-18d6f316ad75', f: true }); done = true; } }; })();</script>";

[_mainWebView stringByEvaluatingJavaScriptFromString:temp];

这是我的空白webView...:(

enter image description here

最佳答案

您不需要在 JavaScript 中包含 script 标记。 stringByEvaluatingJavaScriptFromString 尝试直接在 Web View 中执行给定的 JavaScript 字符串。

尝试这样:

NSString *temp =@"(function () { var done = false; var script = document.createElement('script'); script.async = true; script.type = 'text/javascript'; script.src = 'https://app.purechat.com/VisitorWidget/WidgetScript'; document.getElementsByTagName('HEAD').item(0).appendChild(script); script.onreadystatechange = script.onload = function (e) { if (!done && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) { var w = new PCWidget({ c: 'ea5935c8-1f44-4172-bcd7-18d6f316ad75', f: true }); done = true; } }; })();";

关于javascript - 在 UIWebView 上加载 javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29120181/

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