我目前正在使用Crossrider编写扩展程序,并且需要直接使用URL加载图像以对其进行一些图像处理。然而,onload
事件似乎并没有被解雇。JavaScript从Crossrider浏览器扩展中的URL加载图像
我做错了什么,或者甚至有可能在浏览器扩展中做到这一点?
下面是相关的代码:
var imga = document.createElement('img');
imga.src = obj.attr('href'); // URL of the image
imga.style.display = 'none';
imga.onload = function() {
alert('Image loaded');
var imgData = getImageData(imga, 0, imga.height - 3);
alert('Got Image data');
};
编辑
下面是完整的代码
function readImage(obj)
{
console.log('Reading');
relayReadImage(obj.attr('href'));
}
function relayReadImage(link)
{
var dateObj = new Date();
var newlink = link + "?t=" + dateObj.getTime();
console.log(newlink);
appAPI.request.get(
{
url: newlink,
onSuccess: function(response, additionalInfo) {
console.log(response);
},
onFailure: function(httpCode) {
alert('GET:: Request failed. HTTP Code: ' + httpCode);
}
});
}
尝试在'.onload'后面设置'.src'属性**。它可能被缓存。另一种选择是将查询字符串添加到“src”中,以便它打破任何缓存。我宁愿使用我的第一个建议 – Ian 2013-05-06 17:01:41
刚刚尝试过,没有工作。 – 2013-05-06 18:04:46