JS Picture upload compatibility issue (get picture width is high compatible)

Source: Internet
Author: User

The original code (360 security browser speed mode is not compatible)

function Imgauto (i, MAXW, maxh) {var o = new Image ();    O.SRC = I.SRC; var w = o.width;//w equals null, the problem does not appear on other browsers}

The picture needs to be reloaded again.

function Imgauto (i, MAXW, maxh) {var o = new Image ();    O.onload = function () {var w = o.width; } O.SRC = I.src;}

Note:

Write the onload to the front, first tell the browser how to handle the picture, and then specify the source of the image, so as to avoid IE compatibility issues.

IE will cache the picture, the 2nd load of the picture, not uploaded from the server, but from the buffer load, not IE did not trigger the OnLoad event, but because the speed of loading the buffer is too fast, so that when not running to Img.onload, the onload event has been triggered. This makes me think of Ajax, when writing XMLHTTP, is the first to specify the Onstatechange callback function, and then send the data, the truth is the same.


JS Picture upload compatibility issue (get picture width is high compatible)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.