1

Possible Duplicate:
How pass a value from javascript to objective-C

I want to pass a text variable from JavaScript to an Objective-C variable.

My HTML file looks like this:

<p>Bitte tragen Sie die Document ID ein:</p>

<SCRIPT TYPE="text/javascript">
    function testResults(form){
        location.href = DocumentID.value;
    }
</SCRIPT>

<form action="">
  <table border="0" cellpadding="5" cellspacing="0" bgcolor="#E0E0E0">
    <tr>
      <td align="right">Document ID:</td>
      <td><input name="DocumentID" type="text" size="30" maxlength="30" value="35060e6242160705744ffd8e280005b9"></td>
    </tr>
        <tr>
      <td align="right">Formular:</td>
      <td>
        <input type="button" NAME ="button" value=" Absenden " onClick="testResults(this.form)">
        <input type="reset" value=" Abbrechen">
      </td>
    </tr>
  </table>
</form>

This is the Objective-C code:

-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {


    if([request.URL.relativeString isEqualToString:@"http://localhost:8888/"])
    //if([request.URL.relativeString rangeOfString:@"http://localhost:8888/"].location)
    {
        //self.URL
        [self loadData];

        return true;
    }
   return true;
}

Can somebody give me a hint? Thanks!

1
  • based on which native event you want to fire javascript event?... Commented Dec 20, 2012 at 11:52

1 Answer 1

1

In javascript, make it so that the form submission sets a variable in javascript and then loads a dummy url.

You capture that url in Obj-C like you have done above and then call a function in javascript to return the variable.

NSString *script = [NSString stringWithFormat:@"myfunc('%@')", html];
NSString *result = [self.webView stringByEvaluatingJavaScriptFromString:script];

So myfunc in javascript returns the form variable.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.