就昨天的问题在开一贴:js:怎样只打印Iframe 里面的内容?

yypt111 2003-07-29 09:05:14
原贴:
http://expert.csdn.net/Expert/topic/2079/2079712.xml?temp=.9029047
如题
...全文
343 5 打赏 收藏 举报
写回复
5 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
river168 2003-07-29
  • 打赏
  • 举报
回复
你也可以不要上面这个小控制窗口,直接放在你的父体里控制. (自己改代码)

ScriptX.cab 包,你可以在网上下载, 找不到我可以发给你. 主要作用是修改页眉和页尾, 即那些讨厌的文件名/URL之类的,改为自己想要的东西. 还有个参数设置的页面没有贴上来.你可以直接改
function setupParam(header,footer) {
document.form1.header.value=header;
document.form1.footer.value=footer;
}
以达到效果.

此脚本的直接打印大多数IE都不会弹出打印提示框,但也有极个别的会.
river168 2003-07-29
  • 打赏
  • 举报
回复
以下是弹出窗体(模态,位于打印窗体之上,用于控制打印)的代码:存为HTML文件

<HTML>
<HEAD>
<TITLE>打印管理</TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="James Yu (海阔天空.net)">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</HEAD>

<BODY onload="this.focus()" onunload="closeWin()">
<form name="form1" method="post" action="">
<table width="90px" border="0" cellspacing="0" cellpadding="5">
<tr>
<td> <input type="hidden" name="header" value=""><input type="hidden" name="footer" value=""><input type="hidden" name="num" value=""></td>
</tr>
<tr>
<td align="center">
<input type="button" name="Button" value="打印设置" onclick="printsetup()" class="input_b">
</td>
</tr>
<tr>
<td align="center">
<input type="button" id="preview" name="Submit2" value="打印预览" onclick="previewPage()" class="input_b">
</td>
</tr>
<tr>
<td align="center">
<input type="button" id="printParam" name="Submit32" value="打印参数" onclick="openSetupWin()" class="input_b">
</td>
</tr>
<tr>
<td align="center">
<input type="button" name="Submit3" value="立即打印" onclick="printNow()" class="input_b">
</td>
</tr>
<tr>
<td align="center">
<input type="button" name="Submit34" value="关闭窗口" onclick="closeWin()" class="input_b">
</td>
</tr>
</table>
</form>
</BODY>
</HTML>
<script language="JavaScript">
<!--
var parWindow;
var parMap;
if (window.showModelessDialog){
var j = 0;
for(j=0;j<window.dialogArguments.length;j++)
{
// alert(window.dialogArguments[j].name);
if (window.dialogArguments[j] != null)
{
switch (window.dialogArguments[j].name) {
case "PRINT_Body":
{
parWindow = window.dialogArguments[j];
break;
}
case "myMap":
{
parMap = window.dialogArguments[j];
break;
}
default:
{
// parLayer = window.dialogArguments[j];
break;
}
}
}
}
}else
{
parWindow=window.opener;
}

var str=navigator.appVersion;
for(i=0;i<2;i++)
{
sver=str.substr(5);
sver=sver.substr(0,sver.indexOf(";"));
str=str.substr(str.indexOf(";")+2);
}
//alert(sver);
if (parseInt(sver)<5.5){
eval("document.getElementById('preview')['disabled']='true'");
//eval("document.getElementById('printParam')['disabled']='true'");
}

function printNow(){
tranSetup();
//parWindow.factory.printing.print(true,parWindow);
try{
parWindow.WebBrowser.ExecWB(6,2);
//window.print();
//parWindow.callResumeSetup();
}catch(e)
{
}
}
function previewPage(){
tranSetup();
parWindow.WebBrowser.ExecWB(7,1);
//parWindow.callResumeSetup();
}
function printsetup(){
parWindow.WebBrowser.ExecWB(8,1);
}
function closeWin()
{
try{
self.close();
parWindow.WebBrowser.ExecWB(45,1);
window.opener.close();
}catch(e)
{
//alert(e.description);
}
}

window.name = "PRINT_Manager";
var winParam;
var arrArgus = new Array(2);
arrArgus[0] = this;


function openSetupWin()
{
if (winParam!=null){ winParam.close();}

var h = document.form1.header.value;
var f =document.form1.footer.value;

if (window.showModelessDialog){
//win=window.showModelessDialog("temp.html",window,"dialogwidth:10;dialogtop:100;dialogleft:"+(window.screen.width-150)+";dialogheight:"+(32*window.screen.width/800)+";help:0;status:0;");
winParam=window.showModelessDialog("/common/printParameter.asp?header="+h+"&footer="+f,arrArgus,"dialogwidth:9;dialogtop:330;dialogleft:"+(window.screen.width-150)+";dialogheight:200px;help:0;status:0;");
}
else{
winParam=window.open("/common/printParameter.asp?header="+h+"&footer="+f,"dialog","height=220px,width=100px,top=320,left="+(window.screen.width-150)+",scrollbars=no,resizable=no");
}
}

function setupParam(header,footer) {

document.form1.header.value=header;
document.form1.footer.value=footer;
/*
factory.printing.header = "-"
factory.printing.footer = "-"
factory.printing.Print(true)
factory.printing.leftMargin = 0.2
factory.printing.topMargin = 0.5
factory.printing.rightMargin = 0.2
factory.printing.bottomMargin = 1.5 */
}

function tranSetup()
{
/*
header:
1: '&b&p / &P'
2: '&b 第&p页 / 总&P页'
3: ''
footer:
1: '&b&d'
2: '&b&D'
3: ''
*/

var h=document.form1.header.value;
var f=document.form1.footer.value;
parWindow.callTranSetup(h,f)
}

//-->
</script>
river168 2003-07-29
  • 打赏
  • 举报
回复
从项目里面摘出来,你要自己调试一下.也可以改为其他模式,我是弹出一个模态窗口来进行打印控制.

以下代码存为一个JS文件, 在需要打印的窗体里调用.
/*####################################################################
'# Author : James Yu (海阔天空.net)
'# Create date : 2002-11-29
'# Purpose :
'####################################################################*/

document.open();
document.writeln('<object id="closewin" type="application/x-oleobject"classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11">');
document.writeln('<param name="Command" value="Close">');
document.writeln('</object>');
document.writeln('<object id="WebBrowser" width=0 height=0 classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2">');
document.writeln('</object>');
document.writeln('<OBJECT id="factory" style="DISPLAY: none" codeBase=/include/js/ScriptX.cab#Version=5,60,0,360 classid=clsid:1663ed61-23eb-11d2-b92f-008048fdd814 viewastext>');
document.writeln('</OBJECT>');
document.close();


window.name = "PRINT_Body";
window.onunload=closeManager;
var win;
var arrArgus = new Array(3);
arrArgus[0] = this;
arrArgus[1] = "test";

// var oldh=factory.printing.header;
// var oldf=factory.printing.footer;

closeManager();
if (window.showModelessDialog){
win=window.showModelessDialog("/common/printManager.htm",arrArgus,"dialogwidth:7;dialogtop:100;dialogleft:"+(window.screen.width-150)+";dialogheight:230px;help:0;status:0;");
}
else{
win=window.open("/common/printManager.htm","dialog","height=220px,width=100px,top=100,left="+(window.screen.width-150)+",scrollbars=no,resizable=no");
}

/* function setupParam(header,footer,num) {
var h=factory.printing.header;
var f=factory.printing.footer;
var leftm=factory.printing.leftMargin;
var topm=factory.printing.topMargin;
var rightm=factory.printing.rightMargin;
var bottomm=factory.printing.bottomMargin;

alert(header);
alert(footer);
alert(num);

factory.printing.header = "-"
factory.printing.footer = "-"
factory.printing.Print(true)
factory.printing.leftMargin = 0.2
factory.printing.topMargin = 0.5
factory.printing.rightMargin = 0.2
factory.printing.bottomMargin = 1.5
}*/
function callTranSetup(h,f)
{
/*
header:
1: '&b&p / &P'
2: '&b 第&p页 / 总&P页'
3: ''
footer:
1: '&b&d'
2: '&b&D'
3: ''
*/

//h=h.trim();
//f=f.trim();
try{
if(factory.printing!=null){
switch (h) {
case "1" :
factory.printing.header="&b&p / &P";
break;
case "2" :
factory.printing.header="&b 第&p页 / 总&P页";
break;
case "3" :
factory.printing.header="";
break;
default :
factory.printing.header="";
break;
}
//alert(factory.printing.header);
}
if(factory.printing!=null){
switch(f) {
case "1":
factory.printing.footer="&b&d";
break;
case "2":
factory.printing.footer="&b&D";
break;
case "3":
factory.printing.footer="";
break;
default :
factory.printing.footer="";
break;
}
//alert(factory.printing.footer);
var objs=document.getElementsByName("pageBreak");
for(var i=0;i<objs.length;i++)
objs[i].style.display="";
}
}catch(e)
{
alert(e.description);
}
}

function callResumeSetup()
{
// factory.printing.header=oldh;
// factory.printing.footer=oldf;
// factory.printing.copies=1;
var objs=document.getElementsByName("pageBreak");
for(var i=0;i<objs.length;i++)
objs[i].style.display="none";
}

function closeManager()
{
if (win!=null){ win.close();}
}
New_bug 2003-07-29
  • 打赏
  • 举报
回复
frame名.document.execCommand("Print");
yypt111 2003-07-29
  • 打赏
  • 举报
回复
没人回答,up一下
相关推荐
发帖
.NET社区

6.1w+

社区成员

.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
帖子事件
创建了帖子
2003-07-29 09:05
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。