Reputation: 15136
I'm loading Google Maps API dynamically using this function:
App.prototype.loadScript = function(src) {
$(document.createElement("script")).attr({
type: "text/javascript",
src: src
}).appendTo("body");
};
I pass this URL as the argument:
"//maps.googleapis.com/maps/api/js?v=3.8&sensor=false&language=" + locale + "&callback=window.app.googleMapsCallback"
It works fine the first time I load the page, and the callback fires. However, when I reload the page on Android, window.app.googleMapsCallback does not fire. It works fine in Chrome and in the iOS browser.
It's like the script is cached, and is just not reloaded again. I've tried adding a timestamp parameter to the URL but that didn't help.
How can I make sure the callback always fires?
UPDATE:
Upon further testing, clearing the cache and reloading doesn't work either. I have to clear out all browser data (via Settings -> Applications -> Manage applications) to reload the page successfully.
Using a top level function as a callback makes no difference.
There are no JavaScript errors on reload.
I should mention that I'm using an HTC Evo 4G with Android 2.3.4, and my application is built with jQuery Mobile.
Upvotes: 0
Views: 1764
Reputation: 8254
I've been trying to reproduce your problem using the Android emulator (both versions 2.3.3 and 2.3.5. there is no 2.3.4 version, sorry), but I haven't been able to. The callback runs fine on each page reload.
This is the test jsfiddle: http://jsfiddle.net/MartinodF/gbAuL/. It only includes the minimal code to test your problem and to exclude it depends on something else in your code base.
Could you please try it on your phone? Click "Debug on mobile" (the button on the right of "Run" in the top bar) in jsfiddle, and open up the url it gives you (something like http://jsfiddle.net/m/ABC) in the Android browser. You should get a popup saying "callback called". Try to reload the page, and see if it works.
If it doesn't, then I can try and get my hands on a 2.3.4, HTC Sense skinned device for further testing.
Upvotes: 1