$('#my_button').on('click', function (e) {
var iframe = document.createElement('iframe');
iframe.id = "my_iframe";
iframe.onload = function() {
var doc = iframe.contentDocument || iframe.contentWindow.document;
doc.getElementsByTagName('body')[0].innerHTML = "<p>test123</p>";
iframe.contentWindow.focus();
iframe.contentWindow.print();
$("#my_iframe", top.document).remove();
};
document.getElementsByTagName('body')[0].appendChild(iframe);
});
線がなくてremove
もきれいに印刷されます。ただし、この行はを実行する前に をremove
削除します。iframe を印刷してから削除するように、ある種のコールバックを設定するにはどうすればよいですか?iframe
print()
ありがとう。