i m using google api v3 in my apps. to find direction, i need to pass my current location & destination to java script. google api v3 use java script to use map fu开发者_高级运维nctionalities.
i use following to pass variable. but did not work.
[webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"Handler.method(%@);", str]];
how can i pass variable from obj c to javascript..???
i pass value to a native html page from my web view application through URL
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@?bob=123&frank=321&tom=213", base]];
NSURLRequest *req = [NSURLRequest requestWithURL:url];
[webView loadRequest:req];
The value has been passed to html page and javascript with the URL At Javascript use the following function to get value
function gup( name )
{
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( window.location.href );
if( results == null )
return "";
else
return results[1];
}
now call this function with parameter name of the value
var userLat=(gup( 'bob' ));
this will return the value 123
hope this helps.....:)
精彩评论