2014-04-04 29 views
0

上的css在主页上,我尝试打印一个弹出窗口。 在Chrome上它可以工作,但在Firefox中它不起作用,它忽略了css文件。Firefox在无限循环中挂起并忽略window.print()

在Firefox中,窗口正在载入内容,但我不知道它是什么,因为我无法打开萤火虫。 格式化HTML看起来不错,但打印机不能获取css信息。 所以我虽然可以,因为他加载了一些东西。

HTML+JS代码(小提琴不允许document.write):

http://pastebin.com/QXASsTXg

popup.css

http://pastebin.com/HM6JEMnX

对不起引擎收录,但代码是为大计算器。

Javascript Code

$(document).ready(function() { 

    $('.depart span').click(function(){ 

     //close all popups 
     $('.popup').hide(); 

     //open current popup 
     $(this).next().slideDown(); 
    }); 

    $('.close').click(function(){ 
    // close all popups  
     $('.popup').slideUp(); 

    }); 

    $('span.printbutton').click(function(){ 
    printPopup($(this)); 
    }); 
}); 
function printPopup(data){ 
    var popup = data.parent().parent().parent('div.popup'); 
    mywindow = window.open('', 'my div', 'height=600,width=420'); 
    mywindow.document.write('<html><head><title>Popup</title>'); 
    mywindow.document.write('<link rel="stylesheet" media="screen" href="popup.css" type="text/css" />'); 
    mywindow.document.write('<link rel="stylesheet" media="print" href="popup.css" type="text/css" />'); 

    mywindow.document.write('</head>') 
    mywindow.document.write('<body class="popupwindow">') 
    mywindow.document.write('<div class="popup">') 

    mywindow.document.write(popup.html()); 
    mywindow.document.write('</div>') 

    mywindow.document.write('</body></html>'); 
// mywindow.location.reload(); 
    mywindow.focus(); 
    mywindow.print(); 
    setTimeout('mywindow.close();', 5000); 

    return true; 
} 

希望有人能够帮助。

编辑:一个新的提示发现,当弹出加载循环时,我不得不按下ESC键以取消循环,然后我可以按STRG + P,它工作正常。 哪里可能是错误?

回答

0
Throurg Jquery Pull Css from That Printout Page 
INSTEAD OF : 
    mywindow.document.write('<link rel="stylesheet" media="screen" href="popup.css" type="text/css" />'); 
    mywindow.document.write('<link rel="stylesheet" media="print" href="popup.css" type="text/css" />'); 

    USE : $("#printoutpage").css(); 

See If It Works 
+0

弹出窗口看起来不错,也是css信息。 唯一的问题是,打印机不能获取信息。 – demonking

+0

Awwesssome @demonking – vijay

0

尝试引用的绝对路径CSS文件:

mywindow.document.write('<link rel="stylesheet" media="screen" href="\path\to\css\popup.css" type="text/css" />'); 
mywindow.document.write('<link rel="stylesheet" media="print" href="\path\to\css\popup.css" type="text/css" />'); 
+0

Popup的工程很棒,但打印机没有收到css信息。 – demonking

+0

你测试过了吗?您的浏览器可能找不到css文件的路径...您应该设置绝对路径并尝试再次打印... –

+0

是的,我已经测试过它,但它不起作用。 打印机只获取没有css的信息 – demonking

1

我有固定它自己,如果别人有同样的问题,这是解决方案:你上次

mywindow.document.write('</html>'); 

你需要这条线的Firefox:

mywindow.document.close(); 

之后,Firefox停止等待其他内容,我可以打印弹出没有问题。 不知何故,铬是忽略了缺失的行,我工作正常,但Firefox需要它正常工作。