Javascript图像 - 访问头响应 [英] Javascript Image - access headers in response

查看:118
本文介绍了Javascript图像 - 访问头响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当更改Javascript Image对象的.src属性时,请求将发送到指定的URL。

When changing the .src property of a Javascript Image object, a request is send to the specified URL.

// new image object    
var imgObject = new Image();

// assign the path to the image to the src property   
imgObject.src = 'http://mydomain.com/' + 'image/image.jpg';

服务器的响应包含头像任何其他响应。
我的问题是:一旦服务器发送响应,是否有一种访问Image对象的onready,onload或onreadystatechange事件的方法?

The server's response contains headers like any other response. My question is: is there a way to access this headers in the onready, onload or onreadystatechange events of the Image objects once the server sent the response?

谢谢。

推荐答案

不,没有。如果您使用自己的ajax调用自己下载了图像,这些标题将仅适用于您。当浏览器通过 .src 属性自动下载时,浏览器不会使图像标题可用。

No, there is not. The headers would only be available to you if you downloaded the image yourself with your own ajax call. The browser doesn't make the image headers available when it automatically does the downloading via the .src property.

您可能还需要记住,浏览器喜欢在浏览器缓存中缓存图像,从那里加载时,它们也不会有标题。

You may also want to keep in mind that the browser likes to cache images in the browser cache and when loaded from there, they wouldn't have headers either.

这篇关于Javascript图像 - 访问头响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆