打开新窗口后,print()在IE中不起作用.它适用于Chrome.这是一个测试人员:
<html>
<head>
<script type="text/javascript">
function openWin()
{
myWindow=window.open('','','width=200,height=100');
myWindow.document.write("<p>This is 'myWindow'</p>");
myWindow.focus();
myWindow.print(); //DOES NOT WORK
}
</script>
</head>
<body>
<input type="button" value="Open window" onclick="openWin()" />
</body>
</html>
Run Code Online (Sandbox Code Playgroud) 我有以下JavaScript代码:
$(document).ready(function() {
$('a#print_button').click(function(event) {
event.preventDefault();
var print_url = 'print.html';
if ($('#print_page').length == 0) {
$("body").append('<iframe id="print_page" name="print_page" src=' + print_url + ' style="display: none; @media print { display: block; }"></iframe>');
} else {
$('#print_page').attr("src", print_quote_url);
}
$('#print_page').on("load", function() {
frames["print_page"].focus();
frames["print_page"].print();
});
});
});
Run Code Online (Sandbox Code Playgroud)
它适用于Chrome和Firefox.但是当我点击IE上的按钮时,它会打印父页面,而不是打印iframe.
我必须以div下列方式打印出我正在做的事情:
function PrintElem(elem)
{
Popup(elem.html());
}
function Popup(data)
{
var mywindow = window.open('', 'to print', 'height=600,width=800');
mywindow.document.write('<html><head><title></title>');
mywindow.document.write('<link rel="stylesheet" href="css/mycss.css" type="text/css" />');
mywindow.document.write('</head><body >');
mywindow.document.write(data);
mywindow.document.write('</body></html>');
mywindow.print();
mywindow.close();
return true;
}
Run Code Online (Sandbox Code Playgroud)
我的问题是在IE上,当我点击按钮时没有任何反应.但是,在Chrome和Firefox上它可以运行.我该怎么做才能正确打印出来?
编辑:我打电话print给以下方式:
$('#print_it').click(function(){
var element = $('#itinerario');
PrintElem(element);
});
Run Code Online (Sandbox Code Playgroud)
这是print_it按钮的id.
我看到的另一件事是,经过一段时间后,Chrome和其他浏览器告诉我该页面没有响应.为什么会这样?
我是JQuery和Primefaces的新手.
下面的代码(printer.js)在Primefaces中用于打印所需的目标 <p:printer target="targetId">
我正在尝试打印一个位于对话框内的Primefaces面板的内容,它在IE8和其他浏览器中工作正常,但在IE9及以上版本中它会抛出一个错误 "Internet Stopped Working"
How can i Fix this issue ? Can any one Explain what Does that printer.js Do ?
Run Code Online (Sandbox Code Playgroud)
printer.js
(function(b){var a;
b.fn.jqprint=function(d){a=b.extend({},b.fn.jqprint.defaults,d);
var c=(this instanceof jQuery)?this:b(this);
if(a.operaSupport&&b.browser.opera){
var e=window.open("","jqPrint-preview");
e.document.open();
var g=e.document
}else{
var f=b("<iframe />");
if(!a.debug){
f.css({position:"absolute",width:"0px",height:"0px",left:"-600px",top:"-600px"})
}
f.appendTo("body");
var g=f[0].contentWindow.document
}
if(a.importCSS){
if(b("link[media=print]").length>0){
b("link[media=print]").each(function(){g.write("<link type='text/css' rel='stylesheet' href='"+b(this).attr("href")+"' media='print' />")})
}else{
b("link").each(function(){g.write("<link type='text/css' rel='stylesheet' href='"+b(this).attr("href")+"' />")})\
}
}
if(a.printContainer){
g.write(c.outer())
}else{
c.each(function(){g.write(b(this).html())})
}g.close();
(a.operaSupport&&b.browser.opera?e:f[0].contentWindow).focus();setTimeout(function(){(a.operaSupport&&b.browser.opera?e:f[0].contentWindow).print();if(e){e.close()}},1000)
};
b.fn.jqprint.defaults={debug:false,importCSS:true,printContainer:true,operaSupport:true};
jQuery.fn.outer=function(){return b(b("<div></div>").html(this.clone())).html()}
})(jQuery);
Run Code Online (Sandbox Code Playgroud) javascript ×5
printing ×5
jquery ×3
html ×2
document ×1
focus ×1
jsf ×1
primefaces ×1
window ×1