当我点击按钮或菜单进入网络时,我需要获取或捕获执行的 JavaScript 命令UIWebView
我不知道哪个功能使用站点来上传文件,所以我需要捕获它。
这样做的目的是通过点击UIButton
. JS 执行到UIWebView
with[webView stringByEvaluatingJavaScriptFromString:@"js_code_here"];
有什么办法吗?
当我点击按钮或菜单进入网络时,我需要获取或捕获执行的 JavaScript 命令UIWebView
我不知道哪个功能使用站点来上传文件,所以我需要捕获它。
这样做的目的是通过点击UIButton
. JS 执行到UIWebView
with[webView stringByEvaluatingJavaScriptFromString:@"js_code_here"];
有什么办法吗?
试试这个在 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];
}
希望这会有所帮助,谢谢。快乐编码
如果您知道与按钮/菜单关联的元素 id 或类,则可以解析 HTML。