source: [view]
var win, _this = this,
fillDoc = function(w){
var doc = win.document;
doc.open();
doc.write(htmlStr);
doc.close();
_this.normalizeRowHeight(doc);
};
if(!window.print){
//We don't have a print facility.
return;
}else if(dojo.isChrome || dojo.isOpera){
//referred from dijit._editor.plugins.Print._print()
//In opera and chrome the iframe.contentWindow.print
//will also print the outside window. So we must create a
//stand-alone new window.
win = window.open("javascript: ''", "", "status=0,menubar=0,location=0,toolbar=0,width=1,height=1,resizable=0,scrollbars=0");
fillDoc(win);
//Opera will stop at this point, showing the popping-out window.
//If the user closes the window, the following codes will not execute.
//If the user returns focus to the main window, the print function
// is executed, but still a no-op.
win.print();
win.close();
}else{
//Put private things in deeper namespace to avoid poluting grid namespace.
var fn = this._printFrame,
dn = this.grid.domNode;
if(!fn){
var frameId = dn.id + "_print_frame";
if(!(fn = dojo.byId(frameId))){
//create an iframe to store the grid data.
fn = dojo.create("iframe");
fn.id = frameId;
fn.frameBorder = 0;
dojo.style(fn, {
width: "1px",
height: "1px",
position: "absolute",
right: 0,
bottoom: 0,
border: "none",
overflow: "hidden"
});
if(!dojo.isIE){
dojo.style(fn, "visibility","hidden");
}
dn.appendChild(fn);
}
//Reuse this iframe
this._printFrame = fn;
}
win = fn.contentWindow;
fillDoc(win);
// IE requires the frame to be focused for
// print to work, but since this is okay for all
// no special casing.
dijit.focus(fn);
win.print();
}