GalaxyPilot —— D.S


        生命不熄,战斗不止
数据加载中……

打印frame里的内容

代码网上找到的,不能用,也有可能是用法不对,做了一些修改,但还是不能通用,有时间了再说。

function printFrame(frame) {

 if (printIsNativeSupport())
  window.print2 = window.print;
 window.print = printFrame;
 
 if (this.parent.document.frames(frame).document.readyState !== "complete" ){
  return;
 }

 if ( window.print2 ){ // IE5
  var focused = document.activeElement;
  this.parent.document.frames(frame).focus();
  if (this.parent.document.frames(frame).print2)
   this.parent.document.frames(frame).print2();
  else
   this.parent.document.frames(frame).print();
  return;
 }

 var eventScope = printGetEventScope(this.parent.document.frames(frame));
 var focused = document.activeElement;

 window.printHelper = function() {
  execScript("on error resume next: printWB.ExecWB 6, 1", "VBScript");
  printFireEvent(this.parent.document.frames(frame), eventScope, "onafterprint");
  printWB.outerHTML = "";
  window.printHelper = null;
 }

 document.body.insertAdjacentHTML("beforeEnd","<object id=\"printWB\" width=0 height=0 \classid=\"clsid:8856F961-340A-11D0-A96B-00C04FD705A2\"></object>");
 printFireEvent(this.parent.document.frames(frame), eventScope, "onbeforeprint");
 this.parent.document.frames(frame).focus();
 window.printHelper = printHelper;
 setTimeout("window.printHelper()", 0);
}

// helpers
function printIsNativeSupport() {
 var agent = window.navigator.userAgent;
 var i = agent.indexOf("MSIE ")+5;
 return parseInt(agent.substr(i)) >= 5 && agent.indexOf("5.0b1") < 0;
}

function printFireEvent(frame, obj, name) {
 var handler = obj[name];
 switch ( typeof(handler) ) {
  case "string": frame.execScript(handler); break;
  case "function": handler();
 }
}

function printGetEventScope(frame) {
 var frameset = frame.document.all.tags("FRAMESET");
 if ( frameset.length ) return frameset[0];
  return frame.document.body;
}

posted on 2006-05-10 13:48 舵手 阅读(2969) 评论(1)  编辑  收藏

评论

# re: 打印frame里的内容  回复  更多评论   

yu
2012-08-02 09:50 | 6

只有注册用户登录后才能发表评论。


网站导航: