gpt4 book ai didi

javascript - 无法使用 JavaScript 在 IE 上打印 iframe,而是打印父页面

转载 作者:可可西里 更新时间:2023-11-01 02:33:42 28 4
gpt4 key购买 nike

我有以下 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();
});
});
});

它适用于 Chrome 和 Firefox。但是当我点击 IE 上的按钮时,它会打印父页面,而不是打印 iframe。

最佳答案

我一直在寻找在 Internet Explorer 中打印 Iframe 的解决方案。经过数小时的搜索,我得到了解决方案。它对我有用。请检查以下链接

http://bytes.com/topic/misc/answers/629926-ie7-printing-iframe-solution

document.execCommand('print', false, null);

关于javascript - 无法使用 JavaScript 在 IE 上打印 iframe,而是打印父页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17573733/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com