I am on blackberry9300 (5.0.0.832). And I am trying to add a javascript element programmatically.
var script=document.createElement('script');
script.src='file.js';
script.type='text/javascript';
script.onload=function(){alert('loaded');}; //Nothing happens
script.addEventListener('load', function(){alert('loaded');}, false); //Nothing happens
script.addEventListener('readystatechange', function(){alert('state changed');}, false); //Nothing happens
script.onreadystatechange=function(){alert('state changed')}; //Nothing happens
document.getElementsByTagName('head').item(0).appendChild(script);Is there any way to workaround this issue?
blackberry browser on older os (< 6.0) doesn't fire onload events or doesn't change readyState of script. So I need to poll if js file is loaded successfully or not. Here is that function if anybody is interested.
function loadScript(path,callback,chkvar){
var a=document.createElement('script');
a.src=path;
a.type='text/javascript';
a.onreadystatechange=function(){
if(this.readyState=='complete'||this.readyState=='loaded')
callback();
};
a.onload=callback;
if(a.hasOwnProperty('onload')==false)
var e=setInterval(function(){
if(eval(chkvar)){ //chkvar will only be available after js file is loaded.
clearInterval(e);
callback();
}
},50);
}
document.getElementsByTagName('head').item(0).appendChild(a);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With