Detecting WIFI connectivity in Mobile Safari
Is it possible to detect, through Javascript, whether the user is connected to a WIFI or high speed connection as opposed to a slow one? I'm trying to use something like that to load a compressed version of a video if the user is on a slow connection.
Li开发者_如何学Pythonke:
if (onwifi) {
//heavy video
} else { //light video}
Yes, you can gauge the connection speed.
Create a new Date
object, then use the DOM to download an image of a fixed size, with a random number appended on the end so the client doesn't cache it. The image's onload
event should subtract the time before the image was downloaded from the current time, therefore giving you the number of milliseconds it took to download.
var imageurl='http://www.google.com/intl/en_ALL/images/srpr/logo1w.png';
var image=document.createElement('image');
image.src=imageurl+'?'+Math.round(Math.random()*1000);
document.body.appendChild(image);
var imagetook=0;
var date=new Date();
image.onload=function(){
imagetook=getMilliseconds();
startmovie();
}
精彩评论