function myPrint(){
var el = "<img src='//xxx.jpg'>";
var iframe = document.createElement('IFRAME');
iframe.setAttribute('style', 'position:absolute;width:0px;height:0px;left:-500px;top:-500px;');
document.body.appendChild(iframe);
var doc = iframe.contentWindow.document;
doc.write(el);
var ys="html,body{height:100%}img{max-width:100%;max-height:100%;margin:0 auto}";
var style=document.createElement("style");
style.innerText=ys;
doc.getElementsByTagName("head")[0].appendChild(style)
doc.close();
iframe.contentWindow.focus();
iframe.contentWindow.print();
)
js 利用iframe 局部打印
最新推荐文章于 2024-05-14 09:43:28 发布