0

So I was looking to create a UIBarButton, via IBOutlet, and send a JavaScript code to the WebView through this button. This is what I have so far but it keeps returning an error:

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 Error Screenshot


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

^ This being the JavaScript code I want sent to the UIWebView so whatever's located in the Textarea (who's ID is code), will be emailed to [email protected].

Please also specify if theres an easier way to do this.

1 Answer 1

1

The error is being thrown because your string is ending prematurely at the first quotation mark inside it. You need to "escape" the quotations within your string with a backslash:

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.