我希望将jsp中的数据与窗口中的图像一起显示。 以下是我的js代码:
function printPage(id)
{
var html="<html>";
html+="<head>";
html+="</head>";
html+= document.getElementById("img_13").innerHTML;
html+= document.getElementById(id).innerHTML;
var printWin = window.open('','','left=0,top=0,width=auto,height=auto,toolbar=0,scrollbars=0,status=0,
resizable=0');
printWin.document.write(html);
printWin.document.write("<img alt='ALTERNATIVE' src='../Images/calender/cal2.jpg' />");
printWin.document.close();
printWin.focus();
printWin.print();
printWin.close();
}
从jsp我称之为
<div id="receipt">
some data over here
</div>
<div id="img_13">
</div>
<input type="button" value="Print" onclick="printPage('receipt')" >
这里img_13是为该图像创建的css id。它在jsp上显示,但在窗口中不显示在js上。 我也尝试过document.write()与图像的相对路径,但仍然不起作用。
答案 0 :(得分:0)
我得到了解决方案。而不是使用相对路径
<img alt='ALTERNATIVE' src='../Images/calender/cal2.jpg' />
我用绝对路径
<img alt='ALTERNATIVE' src='/ProgectName/Images/cal2.jpg'/>
实际上我以前用绝对路径'/ProgectName/WebContent/ImagesFolder/image_name.png'尝试了这个,这是实际的绝对路径,但是它没有工作。现在我已经从路径中移除了WebContent并且它有效。