我有下面的代码来打印 fancybox 中加载的文本。它在 Chrome 和 Firefox 中完美运行。但在 ie9 中它会打开一个空白窗口并关闭。然后什么也没发生。
jQuery(function($) {
$('a.print').click(function() {
var print_button = '';
var print_page = window.open('', 'Print', 'width=600,scrollbars=yes, height=700');
var html = '<h2><?php print t("Term & Condition"); ?></h2> <br/>' + '<?php echo $body_content; ?>';
print_page.document.open();
print_page.document.write(html);
print_page.print();
print_page.close();
return false;
});
});
最佳答案
更改以下内容:
print_page.document.write(html);
print_page.print();
进入:
print_page.document.write(html);
print_page.document.close();
print_page.focus();
print_page.print();
JSFiddle .
关于javascript - js打印功能在ie9下不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12932755/