我在iOS UIwebView中使用从javascript代码中捕获事件。我通过点击检测命令:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
if (navigationType == UIWebViewNavigationTypeLinkClicked) {
NSString *urlStr = request.URL.absoluteString;
if ([urlStr rangeOfString:@"close"].location == 0) {
[self.delegate fullScreenBannerControllerOnClose:self];
} else if ([urlStr rangeOfString:COMMAND_KEY].location == 0) {
[[Market instance] executeCommand:banner.command]
} else if ([urlStr rangeOfString:@"get_prices"].location == 0) {
[[Shop instance] loadProducts];
}
return NO;
}
return YES;
}
当用户点击html横幅时,一切正常。但现在我需要调用命令手册
我在html中使用:
<a href="get_prices://" id="price_id" ></a>
并在加载调用函数
<body marginwidth="0" marginheight="0" onload="getPrices()">
此功能可手动点击
function getPrices() {
document.getElementById("price_id").click();
};
但我得到命令:
file:///var/mobile/Applications/F4DB923C-27D4-4677-B0DA-C7F0713E5D20/Library/content/dynamic/get_prices://
我的代码等待get_prices
将在字符串的开头,但它最后。如何解决此问题并手动将命令get_prices
发送到我的UIWebView