网络代码如下
<asp:Image runat="server" ID="img1" ImageUrl="~/Images/important.gif" />
<asp:Button ID="btn" runat="server" Text="print" />
我的javascript如下
<script type="text/javascript">
function printIt() {
var win = window.open('', 'Image', 'resizable=yes,...');
if (win) {
//var imgID = '<%= img1.ClientID %>';
var imageControl = document.getElementById('<%=img1.ClientID%>').src;
win.document.write(imageControl);
win.document.close();
win.focus();
win.print();
}
return false;
}
</script>
// 根据vitoshabg
答案更新代码
<script type="text/javascript">
function printIt() {
var win = window.open('', 'Image', 'resizable=yes,...');
if (win) {
//var imgID = '<%= img1.ClientID %>';
var imageControl = document.getElementById('<%=img1.ClientID%>').src;
win.write('<img src="' + imageControl + '">');
//win.write(imgParent);
win.document.close();
win.focus();
win.print();
}
return false;
}
</script>
但是,我得到的不是图片,而是网址,有人可以帮助我在这里获取图片