[英]Loading javascript on UIWebView
I have a javascript
with me and just trying to load that on my UIWebView
,Can't figure out what i am doing wrong. 我有一个
javascript
,只是试图将其加载到我的UIWebView
,无法弄清楚我在做什么错。 Here is my Script: 这是我的脚本:
<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>
And Here is my code: 这是我的代码:
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];
Here is my blank webView
...:( 这是我的空白
webView
... :(
Any help will be much appriciated,Thanks i advance....! 任何帮助将不胜感激,谢谢我前进。
You do not need to include the script tag in the javascript. 您不需要在javascript中包含script标记。
stringByEvaluatingJavaScriptFromString
tries to execute the given javascript string directly in the webview. stringByEvaluatingJavaScriptFromString
尝试直接在stringByEvaluatingJavaScriptFromString
中执行给定的javascript字符串。
Try it this way: 尝试这种方式:
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; } }; })();";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.