javascript手动点击目标在iOS中发送事件

时间:2014-06-05 13:50:46

标签: javascript ios uiwebview

我在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

0 个答案:

没有答案