Jquery jFrame在IE中不起作用但在FF中

时间:2012-03-01 07:47:37

标签: jquery css internet-explorer firefox printing

嘿所有我想让这个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

帮助会很棒!

大卫

1 个答案:

答案 0 :(得分:0)

尝试

jFrame.css( "opacity", "0" ).css( "height", "0px" ).appendTo($("body:first"));

它对我有用。显示:无;将不会被ie。

识别