图像 src(通过 javascript)chrome/firefox 之间不一致
嘿,所以我遇到了一个奇怪的错误/边缘情况。查看以下代码:
var i = new Image();
i.src = 'http://ia.media-imdb.com/images/M/MV5BMTIxOTAxNTc4NF5BMl5BanBnXkFtZTcwOTg1NzQyMQ@@._V1._SX97_SY140_.jpg';
console.log(i.width);
这在 chrome 中工作正常(因为它指的是真实图像),但在 FF 中失败。认为这可能与“at”符号或双扩展名有关(例如“._V1._SX97_SY140_.jpg”),但并不真正知道。
感谢您的任何帮助。
Heya, so I'm running into a weird bug/edgecase. Check out the following code:
var i = new Image();
i.src = 'http://ia.media-imdb.com/images/M/MV5BMTIxOTAxNTc4NF5BMl5BanBnXkFtZTcwOTg1NzQyMQ@@._V1._SX97_SY140_.jpg';
console.log(i.width);
This works fine in chrome (as it's referring to a real image), but fails in FF. Thought it may have to do with the 'at' signs or the double extension (eg. '._V1._SX97_SY140_.jpg'), but don't really know.
Thanks for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请记住,图像是异步加载的。您需要为图像的加载事件分配一个事件处理程序并在那里获取宽度:
keep in mind, that the image is loaded asynchronously. You need to assign a event handler for the load event of the image and get the width there:
403 响应标头意味着 禁止 (wiki),您不是允许访问该资源。
imdb.com 这样做可能是为了防止其图像在其他网站上被热链接。
A 403 response header means Forbidden (wiki), that you are not allowed to access the resource.
imdb.com might be doing this to prevent hotlinking of their images in other sites.