2012-03-01 70 views
0

嘿,我想让这个jFrame在IE8/9中工作,因为它在FF中工作没有问题。jquery jFrame不工作在IE中,但在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

,并帮助将是巨大的!

大卫

+0

看看http://projects.erikzaadi.com/jQueryPlugins/jQuery.printElement/,它也适用于Firefox。 – arunes 2012-03-01 11:11:52

+0

@arunes:这似乎没有工作的一半时间我测试演示网站出来... – StealthRT 2012-03-01 23:10:48

回答

0

尝试

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

它为我工作。显示:无;将不会被ie认可。

相关问题