admin管理员组文章数量:1254262
I am trying to pass 2 parameters to a javascript function.This code webview.loadUrl("javascript: function_to_call();");
works fine without parameters but i couldn't use it with parameters.
This is javascript junction :
function changeLocation(_lon , _lat){
var zoom=16;
var lonLat = new OpenLayers.LonLat( _lon , _lat ).transform(
new OpenLayers.Projection("EPSG:4326"),
map.getProjectionObject());
map.setCenter (lonLat, zoom);
}
And this is how i call it from java :
webView.loadUrl("javascript:changeLocation( -0.1279688 ,51.5077286 );") ;
Edit: I couldn't find the problem and i changed my approach, now i am injecting whole javascript function with desired changes everytime when i need to. It is not best solution but it works. Thank you everyone for your help.
I am trying to pass 2 parameters to a javascript function.This code webview.loadUrl("javascript: function_to_call();");
works fine without parameters but i couldn't use it with parameters.
This is javascript junction :
function changeLocation(_lon , _lat){
var zoom=16;
var lonLat = new OpenLayers.LonLat( _lon , _lat ).transform(
new OpenLayers.Projection("EPSG:4326"),
map.getProjectionObject());
map.setCenter (lonLat, zoom);
}
And this is how i call it from java :
webView.loadUrl("javascript:changeLocation( -0.1279688 ,51.5077286 );") ;
Edit: I couldn't find the problem and i changed my approach, now i am injecting whole javascript function with desired changes everytime when i need to. It is not best solution but it works. Thank you everyone for your help.
Share Improve this question edited Jun 19, 2016 at 19:49 sambomartin 6,8137 gold badges43 silver badges64 bronze badges asked Nov 16, 2010 at 15:03 dirhemdirhem 6211 gold badge12 silver badges25 bronze badges 6-
@dirhem: Is this
loadUrl()
(note: capital U) on theWebView
widget in Java? Or something else? – CommonsWare Commented Nov 16, 2010 at 15:11 - @ CommonsWare Sorry i just mistyped here and yes it is WebView widget's loadUrl function. – dirhem Commented Nov 16, 2010 at 15:18
- Could you post the source code that is giving you trouble? Also, are there any error messages? – Jake Commented Nov 16, 2010 at 15:22
- @ Jake I have posted the source coude and no i am not having any error message. – dirhem Commented Nov 16, 2010 at 15:46
- 1 did you try webView.loadUrl('javascript:changeLocation( "-0.1279688" ,"51.5077286" );') ;? – josh.trow Commented Nov 16, 2010 at 16:06
2 Answers
Reset to default 8What you have looks fine. Here is a sample project that demonstrates an almost identical syntax.
Try changing webView.loadUrl("javascript:changeLocation( -0.1279688 ,51.5077286 );") ;
to webView.loadUrl("javascript:changeLocation( '-0.1279688' ,'51.5077286' );") ;
and maybe getting rid of the ;
I just had a similar problem and I fixed it by adding the ''
around my parameter. I didn't have a semicolon in my solution either and it worked so you may need to remove it.
本文标签: androidhow to call parameterized javascript function in the WebKitStack Overflow
版权声明:本文标题:android - how to call parameterized javascript function in the WebKit? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1740793130a2287008.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论