title: javascript to pass string to native objective-c
body: <p>I want to pass string from a button click from <code>html</code> to <code>ios native objective-c</code>. Here is my <code>html</code> with simple <code>javascript</code>:</p>
  
  <pre><code>&lt;html&gt;
      &lt;head&gt;
          &lt;script language="javascript"&gt;
              function callVrama(vramaID) {
              window.location= "vramaWebShelves://vramaID/"+vramaID;
              }
              &lt;/script&gt;
      &lt;/head&gt;
      &lt;body&gt;
         &lt;button onclick="callVrama('asdfqwer1234')"&gt;Try it&lt;/button&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>And this is my function in <code>UIWebViewDelegate</code>:</p>
  
  <pre><code>- (void)viewDidLoad
  {
      NSURL *url = [[NSBundle mainBundle] URLForResource:@"content"
                                                    withExtension:@"html"];
      NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
  
      [super viewDidLoad];
  
      [_webShelves loadRequest:requestObj];
      _webShelves.delegate = self;
  }
  /// some other codes
  
  - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request
   navigationType:(UIWebViewNavigationType)navigationType {
      NSString *url = [[request URL] absoluteString];
  
      static NSString *urlPrefix = @"vramaWebShelves://vramaID/";
  
      if ([url hasPrefix:urlPrefix]) {
          NSString *vramaID = [url substringFromIndex:[urlPrefix length]];
          NSLog(@"VramasRequest: %@", vramaID);
          return NO;
      }
      else {
          return YES;
      }
  }
  </code></pre>
  
  <p>What seems to be a problem?</p>
  
  <p>I actually follow the tutorial from this <a href="http://pablin.org/2013/08/31/interfacing-with-a-uiwebview-from-a-uiviewcontroller/" rel="nofollow">link</a> and everything work. I just not sure how to change the <code>js function</code> call from tapping on the <code>uiwebview</code> to button. Here is the <code>javascript</code> from him:</p>
  
  <pre><code>&lt;script language="javascript"&gt;
              function resizeText(multiplier) {
                  if (document.body.style.fontSize == "") {
                      document.body.style.fontSize = "1.0em";
                  }
                  document.body.style.fontSize =
                  parseFloat(document.body.style.fontSize) +
                  (multiplier * 0.2) + "em";
              }
  
              function touchStart(event) {
                  sX = event.touches[0].clientX;
                  sY = event.touches[0].clientY;
              }
  
              function touchEnd(event) {
                  var parentNode = event.target.parentNode
                  if ( parentNode != null &amp;&amp; parentNode.nodeName.toLowerCase() == "a" )
                      return;
  
                  if (event.changedTouches[0].clientX == sX &amp;&amp;
                      event.changedTouches[0].clientY == sY) {
  
                      window.location = "nativeAction://hideShow";
                  }
              }
  
              document.addEventListener("touchstart", touchStart, false);
              document.addEventListener("touchend", touchEnd, false);
  
              &lt;/script&gt;
  </code></pre>