Home >Web Front-end >JS Tutorial >js compatible Firefox method to obtain image width and height_javascript skills

js compatible Firefox method to obtain image width and height_javascript skills

WBOY
WBOYOriginal
2016-05-16 15:58:001063browse

The example in this article describes the method of obtaining the image width and height using js compatible with Firefox. Share it with everyone for your reference. The specific implementation method is as follows:

<!doctype html> 
<html> 
<head> 
<meta content="text/html; charset=GBK" http-equiv="Content-Type" /> 
<title>获取Image 宽高</title>
</head> 
<body>
<script>
function newimage(obj) {
  a = new Image();
  var objectURL = window.URL.createObjectURL(obj.files[0]);
  var img= document.getElementById('img')
 img.src = objectURL;
  a.src = objectURL;
 img.onload=function (){
 alert(img.width);
 alert(img.height);
 }
}
</script>
<input id="idcardfile" type="file" name="idcardfile" 
onchange="newimage(this)"/>
<img id="img" style="display: none;">
</body> 
</html>

I hope this article will be helpful to everyone’s JavaScript programming design.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn