Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/437.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用数据而不是window.print事件打开新窗口_Javascript_Html - Fatal编程技术网

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

Javascript 使用数据而不是window.print事件打开新窗口,javascript,html,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

我有以下代码

<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.print()用于
window.open('yourURL.com')

如果你想打开一个新窗口,你需要在你的服务器上为它生成一个页面和一个url

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

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

如果你真的想“打开一个新窗口”,这里有一些代码


像这样的?如果他想将数据传递到一个新页面,他必须使用php表单提交或AJAX请求。在任何一种情况下,在javascript中打开一个新窗口,我的答案都会按要求执行
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;
}