【问题标题】:Get JavaScript command executed while tap on UIWebView获取在点击 UIWebView 时执行的 JavaScript 命令
【发布时间】:2013-03-23 03:52:01
【问题描述】:
我需要获取或捕获当我从UIWebView点击一个按钮或菜单进入网络时执行的 JavaScript 命令
我不知道哪个函数使用站点来上传文件,所以我需要捕获它。
这样做的目的是通过点击UIButton 来上传 javascript 文件。 JS 使用[webView stringByEvaluatingJavaScriptFromString:@"js_code_here"]; 执行到UIWebView
有什么办法吗?
【问题讨论】:
标签:
javascript
iphone
ios
uiwebview
uiwebviewdelegate
【解决方案1】:
试试这个在 xcode 项目中调用 js 文件。,
- (void)markHighlightedString
{
// The JS File
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"HighlightedString" ofType:@"js" inDirectory:@""]; // your js file name
NSData *fileData = [NSData dataWithContentsOfFile:filePath];
NSString *jsString = [[NSMutableString alloc] initWithData:fileData encoding:NSUTF8StringEncoding];
[webview stringByEvaluatingJavaScriptFromString:jsString];
// The JS Function
NSString *startSearch = [NSString stringWithFormat:@"stylizeHighlightedString()"]; // your js function which you want to call
[webview stringByEvaluatingJavaScriptFromString:startSearch];
}
希望这会有所帮助,
谢谢。快乐编码
【解决方案2】:
如果您知道与按钮/菜单关联的元素 id 或类,则可以解析 HTML。