2012-03-07 3 views
0

그래서 IBOutlet을 통해 UIBarButton을 만들고이 버튼을 통해 WebView에 JavaScript 코드를 보냅니다. 이것은 내가 지금까지 무엇을 가지고 있지만, 오류 반환 유지 :JavaScript URL 명령을 UIWebView로 보냄

ViewController.m

- (IBAction)emailCodePhone:(id)sender { 
    NSURL *url = [NSURL URLWithString:@"javascript:location.href="mailto:[email protected]?body="+document.getElementById("code").value;"]; 
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; 
    [webViewPhone loadRequest:requestObj]; 
} 

ViewController.m 오류 Error Screenshot


javascript:location.href="mailto:[email protected]?body="+document.getElementById("code").value; 

^이를 내가 UIWebView에 보내려고하는 JavaScript 코드가 그렇게 whate된다. ver는 Textarea에 있습니다 (ID가 누구입니까 코드) [email protected]으로 이메일을 보냅니다.

쉬운 방법인지 알려주세요.

답변

1

문자열이 문자열의 첫 번째 따옴표로 끝나기 때문에 오류가 발생합니다. 문자열 내의 인용문을 백 슬래시로 이스케이프 처리해야합니다.

NSURL *url = [NSURL URLWithString:@"javascript:location.href=\"mailto:...