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

标签 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

帮助会很大!

大卫

最佳答案

尝试

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

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

关于Jquery jFrame 在 IE 中不起作用,但在 FF 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9512435/

相关文章:

html - 修复 IE 中的 CSS 和其他问题

javascript - 从文本区域获取带有字符串 ("Line no."的行号?

javascript - 使用Each Loop时获取每个父节点的ID

单选按钮集上的 jQuery 单击/更改功能

javascript - 整个页面的导航图标不固定

javascript - 文件下载在 IE 浏览器中无法按预期工作?

Javascript 在谷歌浏览器中工作但在 IE 中被阻止

javascript - 如何在不损害第二个显示器的情况下删除模态和背景

html - 如何使用CSS获取要打印的背景图像?

Javascript,Connect style.display 和 style.transition 问题