Javascript Firefox挂起在一个无限循环中,忽略window.print()上的css
在主页上,我尝试打印一个弹出窗口。 在Chrome上它可以工作,但在firefox上它不工作,不知何故它忽略了css文件 在Firefox中,窗口正在加载一些东西,但我不知道它是什么,因为我无法打开firebug。 格式化HTML看起来不错,但打印机没有获得css信息。 所以我想可能是,因为他装了东西Javascript Firefox挂起在一个无限循环中,忽略window.print()上的css,javascript,jquery,html,css,firefox,Javascript,Jquery,Html,Css,Firefox,在主页上,我尝试打印一个弹出窗口。 在Chrome上它可以工作,但在firefox上它不工作,不知何故它忽略了css文件 在Firefox中,窗口正在加载一些东西,但我不知道它是什么,因为我无法打开firebug。 格式化HTML看起来不错,但打印机没有获得css信息。 所以我想可能是,因为他装了东西 HTML+JScode(fiddle不允许document.write): popup.css: 对于pastebin很抱歉,但是stackoverflow的代码太大了 Javascript代
HTML+JS
code(fiddle不允许document.write
):
popup.css
:
对于pastebin很抱歉,但是stackoverflow的代码太大了
Javascript代码
:
$( 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;
}
$(文档).ready(函数(){
$('.span')。单击(函数(){
//关闭所有弹出窗口
$('.popup').hide();
//打开当前弹出窗口
$(this.next().slideDown();
});
$('.close')。单击(函数(){
//关闭所有弹出窗口
$('.popup').slideUp();
});
$('span.printbutton')。单击(函数(){
打印弹出窗口($(此));
});
});
函数打印弹出窗口(数据){
var popup=data.parent().parent().parent('div.popup');
mywindow=window.open(“”,'mydiv','height=600,width=420');
mywindow.document.write('Popup');
mywindow.document.write(“”);
mywindow.document.write(“”);
mywindow.document.write(“”)
mywindow.document.write(“”)
mywindow.document.write(“”)
mywindow.document.write(popup.html());
mywindow.document.write(“”)
mywindow.document.write(“”);
//mywindow.location.reload();
mywindow.focus();
mywindow.print();
setTimeout('mywindow.close();',5000);
返回true;
}
希望有人能帮忙
编辑:发现一个新提示,当弹出窗口加载循环时,我必须按ESC键取消循环,然后我可以按STRG+p,它工作正常。
错误在哪里?Thurg Jquery从打印输出页面中提取Css
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
而不是:
mywindow.document.write(“”);
mywindow.document.write(“”);
使用:$(“#打印输出页”).css();
看看它是否有效
尝试引用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" />');
mywindow.document.write(“”);
mywindow.document.write(“”);
我自己解决了,如果其他人也有同样的问题,这就是解决方案:
在你最后一次
mywindow.document.write('</html>');
在这一行之后,Firefox停止等待其他内容,我可以毫无问题地打印弹出窗口。
不知何故,Chrome忽略了缺失的一行,我可以正常工作,但firefox需要它才能正常工作。弹出窗口看起来不错,还有css信息。唯一的问题是,打印机没有获得信息。awwessome@demonking弹出窗口效果很好,但打印机没有收到css信息。但是您测试过这个吗?您的浏览器可能找不到css文件的路径。。。您应该设置一个绝对路径,然后再次尝试打印…是的,我已经测试过了,但它不起作用。打印机只获取信息,没有CSS您的状态窗口正在加载内容,但它挂起。。。这听起来像是浏览器试图请求它找不到的东西。如果您无法让firebug正常工作,请尝试其他嗅探器(例如fiddler)查看挂起浏览器的请求……问题是,fiddle说他们不支持document.write;/我还测试了LiveHtp头,没有发送任何内容,所有内容都是hat 200获得的
mywindow.document.close();