2014-01-13 17 views
0

我得到了一個webview,我想從webview HTML表單捕獲輸入。我已經試過,但我不能能有一個人幫我請Javascript返回一個字符串到目標c

這是我的WebView代碼

 // Init Web View 
    UIWebView *webView; 
    webView = [[UIWebView alloc] initWithFrame:boundsRect]; 
    webView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 
    webView.scalesPageToFit = YES; 
    webView.contentMode = UIViewContentModeCenter; 
    webView.multipleTouchEnabled = NO; 
    webView.userInteractionEnabled = YES; 
    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]]; 
    [self addSubview:webView]; 
    [webView release]; 
    return self; 

從web視圖中獲得價值,我用下面的代碼。

NSString* value = [webView stringByEvaluatingJavaScriptFromString:@"document.getElementById('text').value"]‌​; 
NSLog(@"got: %@",value); 
+0

你試過了什麼?您的代碼中沒有任何內容會提示任何嘗試。 – njzk2

+0

我試過這個:NSString * value = [webView stringByEvaluatingJavaScriptFromString:@「document.getElementById('text')。value」]; NSLog(@「got:%@」,value); –

+0

而問題是? '-stringByEvaluatingJavaScriptFromString:'return nil? – Emmanuel

回答