如何在我的UIWebview中注入javascript [英] How to inject javascript in my UIWebview
问题描述
我有一个网页视图,在我的网页视图中我想注入以下javascript代码。请帮助我谢谢..
i have a web view, in my webview i want to inject the following javascript code.Please help me thanks..
推荐答案
[webView stringByEvaluatingJavaScriptFromString:@"your script"];
返回运行脚本的结果。
- (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)脚本参数
Returns the result of running a script. - (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)script Parameters
脚本
The script to run.
返回值
运行结果脚本或如果失败则为零。
The result of running script or nil if it fails.
讨论
每个顶级
入口点的JavaScript执行时间限制为10秒。如果脚本执行的时间超过10秒,则Web
视图将停止执行脚本。这可能发生在您的代码中的随机
位置,因此可能会产生意外后果。这个限制是
,因为JavaScript执行可能导致主线程达到
块,所以当脚本运行时,用户无法与网页进行
的交互。
JavaScript execution time is limited to 10 seconds for each top-level entry point. If your script executes for more than 10 seconds, the web view stops executing the script. This is likely to occur at a random place in your code, so unintended consequences may result. This limit is imposed because JavaScript execution may cause the main thread to block, so when scripts are running, the user is not able to interact with the webpage.
JavaScript分配也限制为10 MB。如果您在JavaScript的总内存分配
上超过此限制,则Web视图会引发
异常。可用性
JavaScript allocations are also limited to 10 MB. The web view raises an exception if you exceed this limit on the total memory allocation for JavaScript. Availability
Available in iOS 2.0 and later.
这篇关于如何在我的UIWebview中注入javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!