I want to get the current target property was clicked hyperlinks treatment now follows:
/ / Determine whether _blank marked with hyperlinks
- (BOOL) isBlankLink: (UIWebView *) webView HttpRequest: (NSURLRequest *) request
{
if (webView == nil | | request == nil)
{
return NO;
}
NSURL * URL = [request URL];
NSString * URLString = [URL absoluteString];
/ / NSLog (@ "_blank contrast with the current connection is labeled");
/ / NSLog (@ "-------------------------------- Current Source URL:% @", URLString); < br />
int aLen = [[webView stringByEvaluatingJavaScriptFromString: @ "document.getElementsByTagName (\" a \ "). length"] intValue];
for (int n = 0; n
/ / Get href js script string
NSString * html = [NSString stringWithFormat: @ "document.getElementsByTagName (\" a \ ") [% d] href.", N];
/ / Get href
NSString * href = [webView stringByEvaluatingJavaScriptFromString: html];
/ / NSLog (@ "Sok number:% d URL:% @", n, href);
if ([URLString isEqualToString: href])
{
/ / NSLog (@ "------------------------ find the same connection with the current Web site, began testing whether marked with _blank ------- ------------------ ");
html = [NSString stringWithFormat: @ "document.getElementsByTagName (\" a \ ") [% d] target.", n];
NSString * target = [webView stringByEvaluatingJavaScriptFromString: html];
if ([target isEqualToString: @ "_blank"])
{
/ / NSLog (@ "-------------------------------------------- - find _blank mark the return yes ");
return YES;
}
else
{
/ / NSLog (@ "-------------------------------------------- --- Mark did not find _blank ");
break;
}
}
}
return NO;
}
This in turn is connected with the collection of elements over the comparative method is very slow. . Who can open a web page affect more correct way for me to get target's property?
Reply:
Reply:
Do not know? "Even the top are not.
Reply:
stringByEvaluatingJavaScriptFromString very time consuming, so you certainly slow too frequent calls friends.
The following is what we use to solve UIWebview not open '_blank' link method, you refer to it.
Although JS I do not know, but I think the following code could be modified to your use.
(Void) webViewDidFinishLoad: (UIWebView *) webView {
NSString * js = @ "\
var d = document.getElementsByTagName ('a'); \
for (var i = 0; iif (d [i]. getAttribute ('target') == '_blank') {\
. d [i] removeAttribute ('target'); \
} \
} \
";
[WebView stringByEvaluatingJavaScriptFromString: js];
}
Reply:
This is not the solution
Only one a look ....
No comments:
Post a Comment