用数据而不是window.print事件打开新窗口

时间:2013-09-11 18:33:24

标签: javascript html

我有以下代码;

<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>

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

有人可以帮忙吗?

谢谢。

2 个答案:

答案 0 :(得分:0)

更改window.print();

window.open('yourURL.com');

答案 1 :(得分:0)

如果您想打开新窗口,则需要在服务器上为其生成一个页面和一个网址。

您可以通过在页面内的模式上打开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;
}
相关问题