打开包含数据而不是 window.print 事件的新窗口

Open new window with data instead of window.print event

本文关键字:新窗口 事件 窗口 print window 包含 数据      更新时间:2023-09-26

我有以下代码;

<div class="firm_name">
<form action="#">
<input type="text" value="" id="name" maxlength="28" />
<p class="spacer2"></p>
<span class="form_text" style="display:block; height:28px; position:relative;"><a href="#" onclick="window.print();window.location.href='thanks.html';"><img src="images/print.png" style="border:none;"/></a></span>
</form>
</div>

如果我想打印新页面,但我想在新页面中显示内容而不是打印它,它工作正常。

谁能帮忙?

谢谢。

更改

window.open('yourURL.com');window.print();

如果要打开一个新窗口,则需要在服务器上生成一个页面和一个URL。

您可以通过在页面内的模态上打开 iframe 来模拟窗口,这不是最好的,但它提供了能够打印的隔离。

或者如果你想通过javascript打开它,你可以做到,但是现在大多数浏览器都不喜欢它,有些会提示用户权限,有些会静默阻止。

如果你真的想"打开一个新窗口",这里有一些代码 http://jsfiddle.net/Victornpb/eWVC2/

function pop(html,top,left,width,height) {
    var popup = window.open("", "", "width="+width+",height="+height+",top="+top+",left="+left+",toolbar=no");
    if(popup){
        popup.document.open();
        popup.moveTo(top,left);
        popup.d = popup.document;
        popup.d.write(html);
    }
    else{
        alert("Popup blocked!");
    }
    return popup;
}