Reputation: 381
I would like this iframe to print multiple times when someone clicks print. This is what I have so far, but it is only printing once. Does anyone have any suggestions? Thanks in advance.
$("#printing").on('click',function(){
var printYesNo = 1;
alert("hi");
for(var count = 1; count < 3; count++) {
$('body').append('<iframe src="flyer.php?userNow='+count+'" id="printIFrame" name="printIFrame"></iframe>');
$('#printIFrame').bind('load',
function() {
window.frames['printIFrame'].focus();
window.frames['printIFrame'].print();
}
);
}
});
Upvotes: 0
Views: 3463
Reputation: 318182
You are giving each element the same ID and name, and then focusing printing etc. It just seems wrong, and doing it a little differently will trigger multiple print dialogs in some browsers (printing an iFrame is not cross browser) :
$("#printing").on('click', function () {
for (var count = 1; count < 13; count++) {
(function(k) {
$('<iframe />', {
id : 'printIFrame' + k,
name : 'printIFrame' + k,
on : {
load: function() {
this.contentWindow.focus();
this.contentWindow.print();
}
},
src : 'flyer.php?userNow=' + k,
}).appendTo('body');
})(count);
}
});
Upvotes: 2