È possibile ottenere l'attributo "webview", con l'aiuto di JavaScript e successivamente è possibile inviare tale attributo e il suo valore al codice Objective C nativo.
Aggiungere questo codice JavaScript nella tua pagina HTML tag script all'interno:
function reportBackToObjectiveC(string)
{
var iframe = document.createElement("iframe");
iframe.setAttribute("src", "callback://" + string);
document.documentElement.appendChild(iframe);
iframe.parentNode.removeChild(iframe);
iframe = null;
}
var links = document.getElementsByTagName("a");
for (var i=0; i<links.length; i++) {
links[i].addEventListener("click", function() {
var attributeValue=links[i].webview; //this will give you your attribute(webview) value.
reportBackToObjectiveC(attributeValue);
}, true);
}
dopo questo tuo metodo webViewDelegate chiamerà:
- (BOOL)webView:(UIWebView *)wView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
{
if (navigationType == UIWebViewNavigationTypeLinkClicked)
{
NSURL *URL = [request URL];
if ([[URL scheme] isEqualToString:@"callback"])
{
//You can get here your attribute's value.
}
}
fonte
2013-12-09 12:36:41
Scegli questa ** http: //stackoverflow.com/questions/5775679/how-can-i-get-name-from-link** –