将值从xcode传递到javascript
我在我的应用程序中使用谷歌api v3。为了找到方向,我需要将当前位置和目的地传递给java脚本。google api v3使用java脚本来使用映射功能 我使用以下命令传递变量。但没有起作用将值从xcode传递到javascript,javascript,objective-c,xcode,Javascript,Objective C,Xcode,我在我的应用程序中使用谷歌api v3。为了找到方向,我需要将当前位置和目的地传递给java脚本。google api v3使用java脚本来使用映射功能 我使用以下命令传递变量。但没有起作用 [webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"Handler.method(%@);", str]]; 如何将变量从obj c传递到javascript…?我通过URL将值从web视图应用程序传递
[webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"Handler.method(%@);", str]];
如何将变量从obj c传递到javascript…?我通过URL将值从web视图应用程序传递到本机html页面
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@?bob=123&frank=321&tom=213", base]];
NSURLRequest *req = [NSURLRequest requestWithURL:url];
[webView loadRequest:req];
该值已通过URL传递到html页面和javascript
在Javascript中,使用以下函数获取值
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];
}
现在使用值的参数名调用此函数
var userLat=(gup( 'bob' ));
这将返回值123
希望这有帮助……:)