从JavaScript中的URL检查图像宽度和高度

从JavaScript中的URL检查图像宽度和高度,javascript,Javascript,如果我只有图像的URL,而没有图像本身,如何检查图像的宽度和高度 i、 Url可能类似于 var img = new Image(); img.onload = function () { alert("height: " + img.height + " width:" + img.width); }; img.src = "https://www.gravatar.com/avatar/d17c95dfa5820a212d979da58bc3435c?s=128&d=id

如果我只有图像的URL,而没有图像本身,如何检查图像的宽度和高度

i、 Url可能类似于

var img = new Image();
img.onload = function () { 
    alert("height: " + img.height + " width:" + img.width); 
};
img.src = "https://www.gravatar.com/avatar/d17c95dfa5820a212d979da58bc3435c?s=128&d=identicon&r=PG";


我想做的是,如果图像尺寸与我期望的不完全一致,就不要在我的页面中插入广告。我不想调整图像大小,我要求图像的尺寸与我期望的尺寸完全一致。

您必须加载图像。你可以试试类似的东西

var img = new Image();
img.onload = function () { 
    alert("height: " + img.height + " width:" + img.width); 
};
img.src = "https://www.gravatar.com/avatar/d17c95dfa5820a212d979da58bc3435c?s=128&d=identicon&r=PG";

您必须加载图像。你可以试试类似的东西

var img = new Image();
img.onload = function () { 
    alert("height: " + img.height + " width:" + img.width); 
};
img.src = "https://www.gravatar.com/avatar/d17c95dfa5820a212d979da58bc3435c?s=128&d=identicon&r=PG";

您必须加载图像。你可以试试类似的东西

var img = new Image();
img.onload = function () { 
    alert("height: " + img.height + " width:" + img.width); 
};
img.src = "https://www.gravatar.com/avatar/d17c95dfa5820a212d979da58bc3435c?s=128&d=identicon&r=PG";

您必须加载图像。你可以试试类似的东西

var img = new Image();
img.onload = function () { 
    alert("height: " + img.height + " width:" + img.width); 
};
img.src = "https://www.gravatar.com/avatar/d17c95dfa5820a212d979da58bc3435c?s=128&d=identicon&r=PG";

如果不加载映像,则无法在客户端完成此操作,除非您请求将映像的大小写入URI,如image200x350.jpg

如果要加载图像并在将其放入文档之前检查图像:

var image = new Image();

image.onload = function() {
    console.log("Height: " + image.height + ", Width: " + image.width);

}

image.src = "http://tes.jpl.nasa.gov/css/homeWelcome.png";

如果不加载映像,则无法在客户端完成此操作,除非您请求在URI中写入映像的大小,如image200x350.jpg

如果要加载图像并在将其放入文档之前检查图像:

var image = new Image();

image.onload = function() {
    console.log("Height: " + image.height + ", Width: " + image.width);

}

image.src = "http://tes.jpl.nasa.gov/css/homeWelcome.png";

如果不加载映像,则无法在客户端完成此操作,除非您请求在URI中写入映像的大小,如image200x350.jpg

如果要加载图像并在将其放入文档之前检查图像:

var image = new Image();

image.onload = function() {
    console.log("Height: " + image.height + ", Width: " + image.width);

}

image.src = "http://tes.jpl.nasa.gov/css/homeWelcome.png";

如果不加载映像,则无法在客户端完成此操作,除非您请求在URI中写入映像的大小,如image200x350.jpg

如果要加载图像并在将其放入文档之前检查图像:

var image = new Image();

image.onload = function() {
    console.log("Height: " + image.height + ", Width: " + image.width);

}

image.src = "http://tes.jpl.nasa.gov/css/homeWelcome.png";

URL不包含有关图像的信息,只包含其URI;您必须加载图像,并将其插入文档中,以便JavaScript对其进行任何处理。谷歌快速搜索“获取图像的高度和宽度而不渲染”可能会出现重复:URL不包含图像的任何信息,只包含其URI;您必须加载图像,并将其插入文档中,以便JavaScript对其进行任何处理。谷歌快速搜索“获取图像的高度和宽度而不渲染”可能会出现重复:URL不包含图像的任何信息,只包含其URI;您必须加载图像,并将其插入文档中,以便JavaScript对其进行任何处理。谷歌快速搜索“获取图像的高度和宽度而不渲染”可能会出现重复:URL不包含图像的任何信息,只包含其URI;您必须加载图像并将其插入文档中,以便JavaScript对其进行任何操作。谷歌快速搜索“无渲染获取图像的高度和宽度”可能会出现以下情况: