在ie中,如果想打印frame中的内容,用window.print(frameid)好像不行,不过可以调用下面js中的printframe方法实现,即printframe(frameid)~
<script language=“jscript“>
if ( printisnativesupport() )
window.print2 = window.print;
window.print = printframe;
// main stuff
function printframe(frame, onfinish) {
if ( !frame ) frame = window;
function execonfinish() {
switch ( typeof(onfinish) ) {
case "string": execscript(onfinish); break;
case "function": onfinish();
}
if ( focused && !focused.disabled ) focused.focus();
}
if ( frame.document.readystate !== "complete" &&
!confirm("the document to print is not downloaded yet! continue with printing?") )
{
execonfinish();
return;
}
if ( window.print2 ) { // ie5
var focused = document.activeelement;
frame.focus();
if ( frame.print2 ) frame.print2();
else frame.print();
execonfinish();
return;
}
var eventscope = printgeteventscope(frame);
var focused = document.activeelement;
window.printhelper = function() {
execscript("on error resume next: printwb.execwb 6, 1", "vbscript");
printfireevent(frame, eventscope, "onafterprint");
printwb.outerhtml = "";
execonfinish();
window.printhelper = null;
}
document.body.insertadjacenthtml("beforeend",
"<object id=\"printwb\" width=0 height=0 \
classid=\"clsid:8856f961-340a-11d0-a96b-00c04fd705a2\"></object>");
printfireevent(frame, eventscope, "onbeforeprint");
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;
}
</script>