嘿,我正在努力让这个 jFrame 在 IE8/9 中工作,因为它在 FF 中工作没有问题。
打印图像的代码是这样的:
function PrintElem(elem)
{
var strFrameName = ("printer-" + (new Date()).getTime());
var jFrame = $( "<iframe name='" + strFrameName + "'>" );
jFrame
.css( "width", "1px" )
.css( "height", "1px" )
.css( "position", "absolute" )
.css( "left", "-9999px" )
.appendTo( $( "body:first" ) )
;
var objFrame = window.frames[ strFrameName ];
var objDoc = objFrame.document;
var theHTML = $(elem).html();
theHTML = theHTML.replace("display:none","display:inline");
objDoc.open();
objDoc.write( "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">" );
objDoc.write( "<html>" );
objDoc.write( "<body>" );
objDoc.write( "<head>" );
objDoc.write( "</head>" );
objDoc.write(theHTML);
objDoc.write( "</body>" );
objDoc.write( "</html>" );
objDoc.close();
objFrame.focus();
objFrame.print();
}
然后我开始这样做:
<div id="printable"><IMG SRC="picturesFromServer.asp?PhotoId=310481" style="display:none;"></div>
<IMG SRC="picturesFromServer.asp?PhotoId=310481" width="240" height="320"><br>
</form>
<input type="button" value="Print Division" onclick="PrintElem('#printable')" />
它在 FF 中可以很好地显示页面并打印出来,但在 IE 中它只显示当前页面。
我正在使用从该网站找到的用于 jFrame 的代码:http://www.bennadel.com/blog/1591-Ask-Ben-Print-Part-Of-A-Web-Page-With-jQuery.htm
帮助会很大!
大卫
最佳答案
尝试
jFrame.css( "opacity", "0" ).css( "height", "0px" ).appendTo($("body:first"));
它对我有用。显示:无;不会被ie识别。
关于Jquery jFrame 在 IE 中不起作用,但在 FF 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9512435/