Thursday, November 10, 2011

Mobile Javascript Links

Before I forget, I wanted to pass on some helpful bookmarks
for mobile javascript:



Here's how you do that mini-scroll on page load to hide the address bar:

   setTimeout(function(){
       // Hide the address bar!
       window.scrollTo(0, 1);
   }, 0);


Here's a very fancy network detector:

/**
 * Original idea:
 * http://stackoverflow.com/questions/4697470/detecting-wifi-connectivity-in-mobile-safari
 *
 * but more importantly here:
 * http://www.thefutureoftheweb.com/blog/image-onload-isnt-being-called
 *
 */
metai.checkNetwork = function( contentId ){

       var imageEl=document.
       createElement('img');
       var imageurl=hostURI+contextRoot+'/image/mobile/login/caution.png';
       imageEl.style.visibility='hidden';
       //imageEl.onload=metai.networkLoad;
       //var imagetook=0;
       var startDate=new Date();
       imageEl.onload=function(){
           var endDate=new Date();
           var latency=endDate.getTime()-startDate.getTime();
           //alert(latency);

           if( latency < 200 ){
               playFast( contentId );
           }else{
               playSlow( contentId );
           }
       }

       imageEl.src=imageurl+'?r='+Math.round(Math.random()*1000);
       document.body.appendChild(imageEl);

}

No comments:

Post a Comment