如何将aspx文件生成的图像加载到html中

时间:2018-02-16 20:37:44

标签: javascript

以下图片:http://www.oscn.net/dockets/GetDocument.aspx?ct=tulsa&cn=SC-2011-361&bc=1014242988&fmt=tif

如何使用javascript下载此图像并以html格式显示?

1 个答案:

答案 0 :(得分:0)

你去.. 如果您需要修改图像的任何属性(大小/颜色增强等),请使用new_elem.setAttribute('attribute', 'value');,就像在HTML <img attribute="value" />中一样

var element = document.getElementById('mytargetlocation');

var new_elem = document.createElement('img');
var locationtoimage = 'https://www.sourcecertain.com/img/Example.png';
/*
Note: if your site uses HTTPS, this file will need to be loaded
over HTTPS, if it doesn't, you could just use the original
URL without downloading the image at all
*/
new_elem.setAttribute('src', locationtoimage);
new_elem.setAttribute('alt', 'image not found at specified URL');
element.append(new_elem);
<div id="mytargetlocation"></div>