Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/383.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在chrome应用程序中设置图像的宽度和高度?_Javascript_Jquery_Ajax - Fatal编程技术网

Javascript 如何在chrome应用程序中设置图像的宽度和高度?

Javascript 如何在chrome应用程序中设置图像的宽度和高度?,javascript,jquery,ajax,Javascript,Jquery,Ajax,通过使用这个,我可以得到默认大小的图像。那么请告诉我如何设置该图像的宽度和高度?您可以在var img=document.createElement('img')下面添加两行 var xhr = new XMLHttpRequest(); xhr.open('GET', 'https://supersweetdomainbutnotcspfriendly.com/image.png',true); xhr.responseType = 'blob'; xhr.onload = function(

通过使用这个,我可以得到默认大小的图像。那么请告诉我如何设置该图像的宽度和高度?

您可以在
var img=document.createElement('img')下面添加两行

var xhr = new XMLHttpRequest();
xhr.open('GET', 'https://supersweetdomainbutnotcspfriendly.com/image.png',true);
xhr.responseType = 'blob';
xhr.onload = function(e) {
var img = document.createElement('img');
img.src = window.URL.createObjectURL(this.response);
document.body.appendChild(img);
};

xhr.send();
img.setAttribute('width', '100');
img.setAttribute('height', '100');