无法使用JavaScript在IE上打印iframe,而是打印父页面 [英] Unable to print an iframe on IE using JavaScript, prints parent page instead
本文介绍了无法使用JavaScript在IE上打印iframe,而是打印父页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
$(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_pagename =print_pagesrc ='+ print_url +' style =display:none; @media print {display:block;}>< / iframe>');
} else {
$('#print_page')。attr(src (),print_quote_url);
$ b $('#print_page')。on(load,function(){
frames [print_page]。 ;
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);
I have the following JavaScript code:
$(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();
});
});
});
It works on Chrome and Firefox. But when I click on the button on IE, it prints the parent page, instead of printing the iframe.
解决方案
I was looking for a solution to print Iframes in Internet Explorer. After hours of search i got the solution. it worked for me. Please check the following link
http://bytes.com/topic/misc/answers/629926-ie7-printing-iframe-solution
document.execCommand('print', false, null);
这篇关于无法使用JavaScript在IE上打印iframe,而是打印父页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文