JavaScript: a simple method for obtaining the original size of page images, javascript pages
This example describes how to obtain the original size of a page image by using JavaScript. We will share this with you for your reference. The details are as follows:
The original width and height are obtained through the Image () object.
This method is not so troublesome. You can directly create an Image () object and assign the src value of img to it to obtain it.
Var img = new Image (); img. src = $ ("# target "). attr ("src"); if (img. complete) {alert ('width: '+ img. width + ', height' + img. height); img = null;} else {img. onload = function () {alert ('width: '+ img. width + ', height' + img. height); img = null ;};}
And do not worry that the new Image object will have an additional http request. The browser has cached the image after loading it. you have no problem with the new N Image objects. Of course, the memory will consume, therefore, img is set to null after use.