index.htm
有一个button控件
点击这个按钮要可以打印
http://community.csdn.net/Expert/PostNew.asp?room=5202
这个页面
要求是:点击button不要用open在新窗口打印;而是点击button什么也没有反应就在打印机直接打印出来
谢谢
------解决方案--------------------------------------------------------
打印机出来?学习~~~~
------解决方案--------------------------------------------------------
帮顶。遇到同样的问题。
------解决方案--------------------------------------------------------
除非用ActiveX,此外没有别的办法,因为Web不会保持不显示的数据。
------解决方案--------------------------------------------------------
实际还是使用了winopen 但是可以将页面移出 屏幕 这样即可达到楼主不想看到窗口的效果
===index.aspx中===========
<script>
function winopen(__URL)
{
window.open(__URL, "打印帮助 ", "toolbar=no,menubar=no,resizable=yes, scrollbars=yes,top=3000px,left=3000 ");
}
</script>
<input type= "button " id= "prtBt " value= "打印帮助 " onclick= "winopen( 'help.aspx?prt=yes '); " />
======help.aspx==========================
<%@ Page Language= "C# " AutoEventWireup= "true " CodeFile= "help.aspx.cs " Inherits= "help " %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns= "http://www.w3.org/1999/xhtml " >
<head runat= "server ">
<title> 无标题页 </title>
<Script language= "JavaScript ">
var hkey_root,hkey_path,hkey_key
hkey_root= "HKEY_CURRENT_USER "
hkey_path= "\\\\Software\\\\Microsoft\\\\Internet Explorer\\\\PageSetup\\\\ "
// 设置页眉页脚为空
function PageSetup_Null()
{
try{
var RegWsh = new ActiveXObject( "WScript.Shell ") ;
hkey_key= "header " ;
RegWsh.RegWrite(hkey_root+hkey_path+hkey_key, " ") ;
hkey_key= "footer " ;
RegWsh.RegWrite(hkey_root+hkey_path+hkey_key, " ") ;
}
catch(e){}
}
// 设置页眉页脚为默认值
function PageSetup_Default()
{
try{
var RegWsh = new ActiveXObject( "WScript.Shell ") ;
hkey_key= "header " ;
RegWsh.RegWrite(hkey_root+hkey_path+hkey_key, "&w&b页码,&p/&P ") ;
hkey_key= "footer " ;
RegWsh.RegWrite(hkey_root+hkey_path+hkey_key, "&u&b&d ") ;
}
catch(e){}
}
// 打印
function PrintPage()
{
PageSetup_Null();
wb.execwb(6,1);
PageSetup_Default();
window.opener = null;
parent.close();
}
</Script>
</head>
<body>
<object classid= "CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 " height=0 id=WB name=wb width=0 VIEWASTEXT> </object>
<form id= "form1 " runat= "server ">
<div>
</div>
</form>
</body>
</html>
=======help.aspx.cs============
protected void Page_Load(object sender, EventArgs e)
{
if(!string.IsNullOrEmpty(Request[ "prt "]))
{
Page.RegisterStartupScript( "printhtml ", " <script> PrintPage(); </script> ");