Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/263.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/368.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
C# 打印页面并关闭它_C#_Javascript - Fatal编程技术网

C# 打印页面并关闭它

C# 打印页面并关闭它,c#,javascript,C#,Javascript,如何打印页面并自动关闭 我通过单击按钮打开一个新窗口/页面: protected void ASPxButton_GenerOrd_Click(object sender, EventArgs e) { string AdrUrl = "Print_Ordo.aspx?SoinId=" + Soin_Id + "&SelId=" + TempId; ClientScript.RegisterStartupScript(this.GetType(), "n

如何打印页面并自动关闭

我通过单击按钮打开一个新窗口/页面:

protected void ASPxButton_GenerOrd_Click(object sender, EventArgs e)
{
         string AdrUrl = "Print_Ordo.aspx?SoinId=" + Soin_Id + "&SelId=" + TempId;
        ClientScript.RegisterStartupScript(this.GetType(), "newWindow", String.Format("<script>window.open('{0}');</script>", AdrUrl));
    }
问题是它不会自动关闭。我试过:

self.close();
window.close();
top.close();
这些都不管用。有什么想法吗

PS:正如我通过Firebug所看到的:

<embed width="100%" height="100%" name="plugin" src="http://172.18.1.253:4001/source/Print_Ordo.aspx?SoinId=4&amp;SelId=9" type="application/pdf">


我想因为这个过程插件,我无法关闭这个窗口。

你可以尝试使用这个-在关闭窗口之前添加
聚焦

<script type="text/javascript">
    window.print();
    window.onfocus = function() { window.close(); }
</script>

window.print();
window.onfocus=函数(){window.close();}

查看控制台,应该有一个错误“脚本可能无法关闭脚本未打开的窗口”。这导致您只能通过windows.open JavaScript方法打开的JavaScript关闭windows。请尝试将脚本放入Body标记中。我不知道这是否会有什么不同,但这仍然比把调用放在html的顶部要好。检查答案
<embed width="100%" height="100%" name="plugin" src="http://172.18.1.253:4001/source/Print_Ordo.aspx?SoinId=4&amp;SelId=9" type="application/pdf">
<script type="text/javascript">
    window.print();
    window.onfocus = function() { window.close(); }
</script>