打印问题(急)

super_paladin 2005-09-20 02:56:44
主窗口组成如下:
<frameset rows="110,*" cols="*" frameborder="NO" border="0" framespacing="0">
<frame src="top.asp" name="top" scrolling="NO" noresize marginheight="0" marginwidth="0">
<frameset name="left1" cols="120,15,*" frameborder="NO" border="0" framespacing="0">
<frame src="left.asp" name="left" frameborder="no" noresize id="left" scrolling="no">
<frame src="mid.htm" name="mid" frameborder="no" noresize id="mid" scrolling="no">
<frame src="main.asp" name="main" marginheight="0" marginwidth="2">
</frameset>
</frameset>

请问我要在top.asp中点击一个写着"打印"字样的图片,实现打印main.asp中的内容的功能该怎么做啊?

...全文
280 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
winderxp 2005-09-22
  • 打赏
  • 举报
回复
Remember: There are 3 parts to this script.

1. Put This Code In The HEAD of Your Page. Start copying here:

<script language="JavaScript">
var gAutoPrint = true; // Tells whether to automatically call the print function

function printSpecial()
{
if (document.getElementById != null)
{
var html = '<HTML>\n<HEAD>\n';

if (document.getElementsByTagName != null)
{
var headTags = document.getElementsByTagName("head");
if (headTags.length > 0)
html += headTags[0].innerHTML;
}

html += '\n</HE>\n<BODY>\n';

var printReadyElem = document.getElementById("printReady");

if (printReadyElem != null)
{
html += printReadyElem.innerHTML;
}
else
{
alert("Could not find the printReady function");
return;
}

html += '\n</BO>\n</HT>';

var printWin = window.open("","printSpecial");
printWin.document.open();
printWin.document.write(html);
printWin.document.close();
if (gAutoPrint)
printWin.print();
}
else
{
alert("The print ready feature is only available if you are using an browser. Please update your browswer.");
}
}

</script>


-------------------------------------------------------------------------------

2. Put This Part In the BODY of Your Page. You need to put the part of the page you want to have printed inside this code. Start copying this part here:

<div id="printReady">
This text here is inside the div code so when you click on the button this is what will print. The other text above will not. This way you will be able to put into your Web pages what you think your readers will want to print and leave out what you think they won't want to print.
</div>




3. Here are two ways you can place the link on your page for people to click on so they can print the page.

This is the text:


<a href="javascript:void(printSpecial())">Print this Page</a>

Here is the button:

<form id="printMe" name="printMe"> <input type="button" name="printMe" onClick="printSpecial()" value="Print this Page"> </form>

super_paladin 2005-09-21
  • 打赏
  • 举报
回复
top.asp 写成如下
<button onclick="print()">打印<button>
<script>
function print()
{
parent.main.focus;
parent.main.print();

}
</script>

以上代码中的print 改个名字才行,问题解决了,在此谢谢各位大哥,特别是andyguo370(andyguo370)
super_paladin 2005-09-21
  • 打赏
  • 举报
回复
TO:andyguo370(andyguo370)
你的方法是打印到了main frame里的内容了,可是打印出来的是自定义的内容,我要打的是原来的内容啊,被替换掉了打印出来也没用了.小弟初学,实在不知道怎么改才能打到原来页面的内容
班门弄斧 2005-09-20
  • 打赏
  • 举报
回复
mark!
andyguo370 2005-09-20
  • 打赏
  • 举报
回复
最后定稿版 top.asp

<button onclick="printOne();printTwo();">打印<button>

<script>
var jscode_onreadystatechange='\<Script Language="JavaScript" For="document" event="onreadystatechange"\>'+'\n'+
'if(parent.main.document.readyState=="complete")'+'\n'+
'{'+'\n'+
' parent.main.focus();'+'\n'+
' parent.main.print();'+'\n'+
'}'+'\n'+
'\<\/Script\>'
</script>

<script>
function printOne()
{
currentpage_htmlcode="hello,world!";
currentpage_htmlcode=currentpage_htmlcode+jscode_onreadystatechange;
parent.main.document.close();
parent.main.document.write(currentpage_htmlcode);
}

function printTwo()
{
currentpage_htmlcode="hello,world!";
parent.main.document.close();
parent.main.document.write(currentpage_htmlcode);
}
</script>
andyguo370 2005-09-20
  • 打赏
  • 举报
回复
改进版 top.asp
<button onclick="print();print();">打印<button> //这里一定要写两个print();

<script>
var jscode_onreadystatechange='\<Script Language="JavaScript" For="document" event="onreadystatechange"\>'+'\n'+
'if(parent.main.document.readyState=="complete")'+'\n'+
'{'+'\n'+
' parent.main.focus();'+'\n'+
' parent.main.print();'+'\n'+
'}'+'\n'+
'\<\/Script\>'
</script>

<script>
function print()
{
currentpage_htmlcode="hello,world!";
currentpage_htmlcode=currentpage_htmlcode+jscode_onreadystatechange;
parent.main.document.close();
parent.main.document.write(currentpage_htmlcode);
}
</script>
zhequhuang 2005-09-20
  • 打赏
  • 举报
回复
function printsub()
{
if (confirm('请单击“确定”按钮开始打印,单击“取消”按钮不打印!'))
{
window.print();
}
}
</script>
......
<form>
<input type="button" name="pintbtn" value="打 印" onclick="printsub();">
</form>
andyguo370 2005-09-20
  • 打赏
  • 举报
回复
top.asp

<button onclick="print()">打印<button>

<script>
var jscode_onreadystatechange='\<Script Language="JavaScript" For="document" event="onreadystatechange"\>'+'\n'+
'if(parent.main.document.readyState=="complete")'+'\n'+
'{'+'\n'+
' parent.main.focus();'+'\n'+
' parent.main.print();'+'\n'+
'}'+'\n'+
'\<\/Script\>'
</script>

<script>
function print()
{
currentpage_htmlcode="hello,world!";
currentpage_htmlcode=currentpage_htmlcode+jscode_onreadystatechange;
parent.main.document.close();
parent.main.document.write(currentpage_htmlcode);
}
</script>
super_paladin 2005-09-20
  • 打赏
  • 举报
回复
我试过javascript:parent.main.print(),也是只打到top.asp.要去见客户了,回来再看有没有哪位大哥提出解决方法的
super_paladin 2005-09-20
  • 打赏
  • 举报
回复
晕了,怎么打都只打top.asp
andyguo370 2005-09-20
  • 打赏
  • 举报
回复
top.asp 写成如下
<button onclick="print()">打印<button>
<script>
function print()
{
parent.main.focus;
parent.main.print();

}
</script>
super_paladin 2005-09-20
  • 打赏
  • 举报
回复
楼上的,只是打到top.asp的内容啊
请问加到哪个位置呢?
<td> <a href="javascript:top.frames[3].print();"><img src="images/top_17.gif"..........
是这样吗?
xjdawu 2005-09-20
  • 打赏
  • 举报
回复
top.frames[3].print();
super_paladin 2005-09-20
  • 打赏
  • 举报
回复
谢谢楼上的,不过我的客户要求打印按扭一定要固定在顶端,我不知道怎么样在上层frame中打印其兄弟frame的子frame里的内容.我现在就要解决的是这个问题
andyguo370 2005-09-20
  • 打赏
  • 举报
回复
2、GetPrintContent.asp 打印内容获取代码
<%
PageNo=Request("PageNo")
PrintPagesCount=Request("PrintPagesCount")
ParameterStr=Request("ParameterStr")

RecsPerPage=30
TableWidth=650

IF PageNo="" Then
'打开数据库获得记录集
Set RecSet=GetMdbStaticRecordset("宣传奖励登记数据库.mdb","Select * From 宣传奖励登记表 Where Paid=False And Remuneration>0 Order By AuthorId,TrueTime Desc")

'计算打印页数
Count=RecSet.RecordCount
IF (Count mod RecsPerPage)<>0 Then
PrintPagesCount=Count\RecsPerPage+1
Else
PrintPagesCount=Count\RecsPerPage
End IF

HTMlCode="<Script>"
HTMLCode=HTMLCode&"parent.PrintPagesCount="&PrintPagesCount&";"
HTMLCode=HTMLCode&"parent.CurrentPageContentReady=false;"
HTMLCode=HTMLCode&"parent.document.all.OkButton.disabled=false;"
HTMLCode=HTMLCode&"</Script>"
Response.Write HTMLCode
Response.End
Else
'根据页号生成当前页的打印内容
PageNo=CInt(PageNo)
Set RecSet=GetMdbStaticRecordset("宣传奖励登记数据库.mdb","Select * From 宣传奖励登记表 Where Paid=False And Remuneration>0 Order By AuthorId,TrueTime Desc")

TitleStr="技术中心宣传奖励登记表"
ShoulderStr1="制表日期:"&Year(Date)&"年"&Month(Date)&"月"&Day(Date)&"日"
ShoulderStr2="第"&PageNo&"页 共"&PrintPagesCount&"页"

HTMLCode=""
HtmlCode=HtmlCode&"<TABLE id=""TableHead"" border=0 cellPadding=5 cellSpacing=1 width="&TableWidth&" style=""font-size:9pt;word-break:break-all"">"
HtmlCode=HtmlCode&"<TBODY>"
HtmlCode=HtmlCode&"<TR>"
HtmlCode=HtmlCode&" <TD colspan=2 Align=center bgcolor=#FFFFFF style=""width:100%; height:13; color:black; font-family:黑体; font-size:15pt; font-weight:bold"">"&TitleStr&"</TD>"
HtmlCode=HtmlCode&"</TR>"
HtmlCode=HtmlCode&"<TR>"
HtmlCode=HtmlCode&" <TD Align=left bgcolor=#FFFFFF style=""width:50%; height:10; color:black; font-family:宋体; font-size:9pt; font-weight:normal"">"&ShoulderStr1&"</TD>"
HtmlCode=HtmlCode&" <TD Align=right bgcolor=#FFFFFF style=""width:50%; height:10; color:black; font-family:宋体; font-size:9pt; font-weight:normal"">"&ShoulderStr2&"</TD>"
HtmlCode=HtmlCode&"</TR>"
HtmlCode=HtmlCode&"</TBODY>"
HtmlCode=HtmlCode&"</TABLE>"

HtmlCode=HtmlCode&"<TABLE id=""TableBody"" border=1 cellPadding=0 cellSpacing=1 width="&TableWidth&" style=""font-size:9pt;word-break:break-all; BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid; BORDER-COLLAPSE: collapse; "">"
HtmlCode=HtmlCode&"<TBODY>"
HtmlCode=HtmlCode&"<TR>"
HtmlCode=HtmlCode&" <TD Align=center bgcolor=yellow style=""width:5%; height:28; color:blue; font-weight:bold"">序号</TD>"
HtmlCode=HtmlCode&" <TD Align=center bgcolor=yellow style=""width:9%; height:28; color:blue; font-weight:bold"">帐号</TD>"
HtmlCode=HtmlCode&" <TD Align=center bgcolor=yellow style=""width:9%; height:28; color:blue; font-weight:bold"">真实姓名</TD>"
HtmlCode=HtmlCode&" <TD Align=center bgcolor=yellow style=""width:60%; height:28; color:blue; font-weight:bold"">文章标题</TD>"
HtmlCode=HtmlCode&" <TD Align=center bgcolor=yellow style=""width:10%; height:28; color:blue; font-weight:bold"">日期</TD>"
HtmlCode=HtmlCode&" <TD Align=center bgcolor=yellow style=""width:7%; height:28; color:blue; font-weight:bold"">稿费</TD>"
HtmlCode=HtmlCode&"</TR>"

RecSet.PageSize=RecsPerPage
PageCount=RecSet.PageCount

Count=0
PageSumMoney=0
IF RecSet.RecordCount<>0 Then
RecSet.AbsolutePage=PageNo
For iPage=1 To RecSet.PageSize
IF RecSet.EOF Then Exit For
RecNo=(PageNo-1)*RecSet.PageSize+iPage

MemberInfoStr=EA_DBO.Get_MemberInfo(RecSet("AuthorId"))
If IsArray(MemberInfoStr) Then
Count=Count+1
PageSumMoney=PageSumMoney+RecSet("Remuneration")
HtmlCode=HtmlCode&"<TR>"
HtmlCode=HtmlCode&" <TD Align=center style=""background:#E4EAFC; width:5%; height:25"">"&Count&"</TD>"
HtmlCode=HtmlCode&" <TD Align=center style=""background:#E4EAFC; width:9%; height:25"">"&MemberInfoStr(1,0)&"</TD>"
HtmlCode=HtmlCode&" <TD Align=center style=""background:#E4EAFC; width:9%; height:25"">"&MemberInfoStr(6,0)&"</TD>"
HtmlCode=HtmlCode&" <TD Align=center style=""background:#E4EAFC; width:60%; height:25"">"&RecSet("Title")&"</TD>"
HtmlCode=HtmlCode&" <TD Align=center style=""background:#E4EAFC; width:10%; height:25"">"&Month(RecSet("AddDate"))&"/"&Day(RecSet("AddDate"))&"</TD>"
HtmlCode=HtmlCode&" <TD Align=center style=""background:#E4EAFC; width:7%; height:25"">"&RecSet("Remuneration")&"</TD>"
HtmlCode=HtmlCode&"</TR>"
End If
RecSet.MoveNext
IF RecSet.EOF Then Exit For
Next
End IF

IF Count<RecsPerPage Then
For I=1 To RecsPerPage-Count
HtmlCode=HtmlCode&"<TR>"
HtmlCode=HtmlCode&" <TD Align=center style=""background:#E4EAFC; width:5%; height:25""></TD>"
HtmlCode=HtmlCode&" <TD Align=center style=""background:#E4EAFC; width:9%; height:25""></TD>"
HtmlCode=HtmlCode&" <TD Align=center style=""background:#E4EAFC; width:9%; height:25""></TD>"
HtmlCode=HtmlCode&" <TD Align=center style=""background:#E4EAFC; width:60%; height:25""></TD>"
HtmlCode=HtmlCode&" <TD Align=center style=""background:#E4EAFC; width:10%; height:25""></TD>"
HtmlCode=HtmlCode&" <TD Align=center style=""background:#E4EAFC; width:7%; height:25""></TD>"
HtmlCode=HtmlCode&"</TR>"
Next
End IF

HtmlCode=HtmlCode&"<TR>"
HtmlCode=HtmlCode&" <TD colspan=5 Align=left bgcolor=""#d0d0d0"" style=""width:93%; height:25; color:blue; font-weight:bold"">本页合计(元)</TD>"
HtmlCode=HtmlCode&" <TD Align=center bgcolor=""#d0d0d0"" style=""width:7%; height:25; color:blue; font-weight:bold"">"&PageSumMoney&"</TD>"
HtmlCode=HtmlCode&"</TR>"

HtmlCode=HtmlCode&"</TBODY>"
HtmlCode=HtmlCode&"</TABLE>"

HtmlCode=HtmlCode&"<TABLE id=""TableFoot"" border=0 cellPadding=5 cellSpacing=1 width="&TableWidth&" style=""font-size:9pt;word-break:break-all"">"
HtmlCode=HtmlCode&"<TBODY>"
HtmlCode=HtmlCode&"<TR>"
HtmlCode=HtmlCode&" <TD Align=center bgcolor=#FFFFFF style=""width:20%; height:10; color:black; font-family:宋体; font-size:9pt; font-weight:normal"">负责人:</TD>"
HtmlCode=HtmlCode&" <TD Align=center bgcolor=#FFFFFF style=""width:60%; height:10; color:black; font-family:宋体; font-size:9pt; font-weight:normal""></TD>"
HtmlCode=HtmlCode&" <TD Align=left bgcolor=#FFFFFF style=""width:20%; height:10; color:black; font-family:宋体; font-size:9pt; font-weight:normal"">制表人:"&"</TD>"
HtmlCode=HtmlCode&"</TR>"
HtmlCode=HtmlCode&"</TBODY>"
HtmlCode=HtmlCode&"</TABLE>"

End IF
%>

<HTML>
<BODY>
<INPUT type="hidden" id="CurrentPagePrintContent" value='<%=HTMLCode%>'>
<Script Language="JavaScript" For="document" event="onreadystatechange">
if(parent.PrintContentIfrm.document.readyState=="complete")
{
parent.CurrentPageContentReady=true;
}
</Script>
</BODY>
</HTML>

3、调用实例 Example.asp
<SCRIPT>
function Print()
{
var CurrTime=new Date();
var WindowHandle=CurrTime.getTime();

var ParameterStr="";
ParameterStr=format_to_javastring(ParameterStr);
var url="Print.asp?WindowHandle="+WindowHandle+"&GetPrintContentProgramURL=GetPrintContent.asp¶meterStr="+ParameterStr;
var left=(window.screen.width-270)/2;
var top=(window.screen.height-50)/2;
window.open(url,"打印","left="+left+",top="+top+",width=270,height=50")
}
</SCRIPT>

<input type="button" value="稿酬打印与支付确认" style="background:#FFF6DC; border-style:normal; font-size: 9pt; cursor:hand" onclick="Print()">
andyguo370 2005-09-20
  • 打赏
  • 举报
回复
以下代码实现从数据库中无提示不间断打印,并显示打印进程,需要我自己写的GetWin控件支持,如果需要可发给你。
1、Print.asp 打印对话框代码

<%
WindowHandle=Request("WindowHandle") '打印窗口句柄
GetPrintContentProgramURL=Request("GetPrintContentProgramURL") '获取打印内容的程序的URL
ParameterStr=Request("ParameterStr") '获取打印内容的程序的参数
%>

<script>
var jscode_onreadystatechange='\<Script Language="JavaScript" For="document" event="onreadystatechange"\>'+'\n'+
'if(parent.PrintWorkAreaIfrm.document.readyState=="complete")'+'\n'+
'{'+'\n'+
' parent.PrintWorkAreaIfrm.focus();'+'\n'+
' parent.PrintWorkAreaIfrm.printrecs();'+'\n'+
'}'+'\n'+
'\<\/Script\>'
</script>

<script>
//创建对象,获取打印窗口句柄并打印
var activexobj='<object id="ThisWin" width=0 height=0 classid="CLSID:9F45B3CE-B183-48DD-BD88-A8B27DCBA9E3" CODEBASE="http://10.75.137.38/GetWin.CAB#version=1,0,0,0"></object>'
var jscode_print='\<Script Language="JavaScript"\>'+'\n'+
'function printrecs()'+'\n'+
'{'+'\n'+
' ThisWin.SearchWin("'+'<%=WindowHandle%>'+'");'+'\n'+
' ThisWin.Execute(6,2);'+'\n'+
'}'+'\n'+
'\<\/Script\>'
</script>

<script>
//当前内容打印完成后的处理(使进程条增加)
var jscode_onafterprint='\<Script Language="JavaScript" For="window" event="onafterprint"\>'+'\n'+
' var ProcessRate=(parent.CurrentPrintPageNo-1)/parent.PrintPagesCount;'+'\n'+
' parent.Percent.innerHTML=Math.round(ProcessRate*100)+"%";'+'\n'+
' parent.ProgressBar.style.width=ProcessRate*250;'+'\n'+
' parent.CurrentPagePrintFinish=true;'+'\n'+
'\<\/Script\>'
</script>

<script>
var PrintPagesCount=0;
var CurrentPrintPageNo=0;
var PrintTimeHandle;
var CurrentPagePrintFinish=true;

var ContentTimeHandle;
var CurrentPageContentReady=false;


function StartPrint() //开始打印
{
if(PrintPagesCount!=0)
{
Percent.innerHTML="0%";
ProgressBar.style.width=0;
PrintTimeHandle=setInterval("CheckPrintStatus()",1000);
}
else
{
alert("没有内容可打印!");
window.close();
}
}

function CheckPrintStatus() //检查整个打印任务是否完成
{
if(CurrentPrintPageNo>PrintPagesCount)
{
clearInterval(PrintTimeHandle);
PrintWorkAreaIfrm.document.close();
PrintWorkAreaIfrm.document.write("");
alert("打印处理完成!共"+PrintPagesCount+"页。");
}
else
{
if(CurrentPagePrintFinish==true&¤tPageContentReady==false)
{
CurrentPagePrintFinish=false;
CurrentPrintPageNo++;
if(CurrentPrintPageNo<=PrintPagesCount)
{
GetPrintContent(CurrentPrintPageNo);
}
}
}
}

function GetPrintContent(PageNo) //获取打印内容,参数为页号
{
document.all.PrintContentIfrm.src="<%=GetPrintContentProgramURL%>?PageNo="+PageNo+"&PrintPagesCount="+PrintPagesCount+"¶meterStr=<%=ParameterStr%>";
ContentTimeHandle=setInterval("CheckContentStatus()",300);
}

function CheckContentStatus() //检查当前打印内容的状态
{
if(CurrentPageContentReady==true)
{
clearInterval(ContentTimeHandle);
CurrentPageContentReady=false;

currentpage_htmlcode=PrintContentIfrm.CurrentPagePrintContent.value;
currentpage_htmlcode=currentpage_htmlcode+activexobj+jscode_onreadystatechange+jscode_onafterprint+jscode_print;
PrintWorkAreaIfrm.document.close();
PrintWorkAreaIfrm.document.write(currentpage_htmlcode);
if(CurrentPrintPageNo==1) CurrentPagePrintFinish=true;
}
}

function Cancel()
{
window.close()
}
</script>

<BODY bgcolor=f1f1f1>
<TABLE border=0 borderColor=#ffffff cellPadding=0 cellSpacing=0 width=250>
<TBODY>
<TR>
<TD width=250 align=center>
<DIV style="line-height:0em; font-size:0pt; border-style:solid; border-width:1; width:250; height:20"></DIV>
<DIV id=ProgressBar style="position: absolute; left: 11; top: 15; line-height: 0em; font-size: 0pt; background-color: blue; width: 0; height: 20; border-style: none; border-width: 0"></DIV>
<FONT id=Percent style="position: absolute; left: 125; top: 18; font-size: 10pt; color: red;"></FONT>
</TD>
</TR>
<TR>
<TD height=10></TD>
</TR>
<TR>
<TD width=250>
<TABLE border=0 borderColor=#ffffff cellPadding=0 cellSpacing=0 width="100%">
<TBODY>
<TR>
<TD align=left width=33%>
<BUTTON id="OkButton" disabled=true onclick="StartPrint()">确 定</BUTTON> 
</TD>
<TD align=center width=33%>
</TD>
<TD align=right width=33%>
<BUTTON id="CancelButton" onclick="Cancel()">取 消</BUTTON> 
</TD>
</TR>
</TBODY>
</TABLE>
</TD>
</TR>
<TR>
<TD>
<IFRAME id="PrintWorkAreaIfrm" src="" height=0 width=0 scrolling="no" border=0 framespacing=0 frameborder=0 ></IFRAME> <!--打印工作IFRAME-->
<IFRAME id="PrintContentIfrm" src="<%=GetPrintContentProgramURL%>?PageNo=&PrintPagesCount=¶meterStr=<%=ParameterStr%>" height=0 width=0 scrolling="yes" border=0 framespacing=0 frameborder=0 ></IFRAME> <!--打印内容获取IFRAME-->
</TD>
</TR>
</TBODY>
</TABLE>
</BODY>

super_paladin 2005-09-20
  • 打赏
  • 举报
回复
请问加到哪个位置呢?
<td> <a href="javascript:top.frame[3].print();"><img src="images/top_17.gif"..........
是这样吗?好像不行
ShiningstarHu 2005-09-20
  • 打赏
  • 举报
回复
在top中加入

top.frame[3].print();

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧