how to call parameterized javascript function in the WebKit?

dirhem picture dirhem · Nov 16, 2010 · Viewed 12.5k times · Source

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.

Answer

CommonsWare picture CommonsWare · Nov 16, 2010

What you have looks fine. Here is a sample project that demonstrates an almost identical syntax.