Send parameters to a local file in a UIWebView?

You are loading the HTML from your own bundle which implies you have full control over it. Why not just parameterize the HTML with the fields you want. You could easily add in some hidden input fields that your javascript could then access.

Say your HTML looked like this.

Up vote 1 down vote favorite 2 share g+ share fb share tw.

I'm working on a native iPhone app. I am able to load a local file index. Html into a UIWebView: webView loadRequest:NSURLRequest requestWithURL:NSURL fileURLWithPath:NSBundle mainBundle pathForResource:@"index" ofType:@"html"isDirectory:NO; The web loads fine.

Now, I would like to load the web with some parameters, in the same way one types this in the browser: URL? Var1=myValue&var2=myValue2 So I can get those values inside the javascript of the html file. Is there any way to send parameters to a local html file?

Thanks! Iphone uiwebview link|improve this question asked Aug 4 '09 at 8:47Hectoret5692924 51% accept rate.

You are loading the HTML from your own bundle which implies you have full control over it. Why not just parameterize the HTML with the fields you want. You could easily add in some hidden input fields that your javascript could then access.

Say your HTML looked like this: Static Field 1: Static Field 2: %@ Now just read this data into a string and format the %@ with some hidden fields like this: NSString *input = @""; NSString *formatted = NSString stringWithFormat:html, input; Then call -loadHTMLString: in the webview. WebView loadHTMLString:formatted baseURL:nil; Is there any reason you couldn't do it that way. Now your javascript can grab the value of the hidden input field with a call to: document.

GetElementsByName('field3')0.value.

No, unfortunately not. You can, however, get around this by setting variables and calling functions / methods in JavaScript using the UIWebView:stringByEvaluatingJavaScriptFromString.

I've got a javascript function defined in the local html file. I can load that file, but, how could I call a javascript function inside that file? I need an example.

– Hectoret Aug 4 '09 at 12:38 webView stringByEvaluatingJavaScriptFromString:NSString stringWithFormat:@"myJavascriptFunction(%f);", 1.0f; – rpetrich Aug 4 '09 at 15:01 Did you get that to work? Does the myJavascriptFunction function get called? In my code it doesn't... how can I check for sure if the call it's being done?

– Hectoret Aug 4 '09 at 16:59.

You can insert in your local html-file a javascript to parse the GET-request Use getget('parameter_name') to get the parameter from request string.

Var=1232123232"; NSString *absoluteURLwithQueryString = theAbsoluteURLString stringByAppendingString: queryString; NSURL *finalURL = NSURL URLWithString: absoluteURLwithQueryString; NSURLRequest *request = NSURLRequest requestWithURL:finalURL cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:(NSTimeInterval)10.0 ; web loadRequest:request.

Then call -loadHTMLString: in the webview. I believe he was avoiding using loadHTMLString instead of loadRequest because it breaks back and forward buttons of the UIWebView.

Marjan's way is the proper way of making it work. As my friend Terence pointed it out, the trick is to use absolute file uri (file://) string when creating the url from string properly. This way?

Character does not get encoded, and webview can load the file properly. NSURL URLWithString: @"file://localhost/Users/sj/Library/Application%20Support/iPhone%20Simulator/5.0/Applications/../PrintingWebView. App/final.

Html? Slide=2"; Or use URLWithString:relativeToURL method NSURL *relativeURL = NSURL fileURLWithPath:NSBundle mainBundle bundlePath; NSURL *u = NSURL URLWithString:@"html/index. Html?

Site=2" relativeToURL:relativeURL.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions