save dialogbox base on Fire fox

__qp.prototype.SaveMgr={
  
  savefile:" ",
   /**
   *  save current web page into file specified
   *  @param {string} type the filename saved
   */   
  save:function(){
    var t=this;
    var br=__q.BrowserMgr;
    if(br.browser==='IE'){
   
    window.document.execCommand( 'saveas');
    }
   
    else{
    //for FF
         t.showSaveDialogBox();
         t.addSaveEvent();
        
       }
   },
// below functions for FireFox
 showSaveDialogBox :function(){
 var t=this;
  if(!t.savePanel)
      {
       t.savePanel=__q.ElementMgr.createNode('div')
       t.savePanel.id='save_div';
        st=t.savePanel.style;
     st.border='1px outset black';
        st.top='200px';
        st.left='400px';
        st.height='100px';
        st.width='400px';
        st.position = 'fixed';
        st.backgroundColor = '#BEBEBE';
        st.overflowY = 'hidden';
        st.overflowX = 'hidden';
        st.zIndex=__q.ConfigMgr.rectZIndex+201;
          
      }
      
     
     if(!t.saveAsDialog)
    {
      
      t.saveAsDialog=__q.ElementMgr.createNode('fieldset');
      st=t.saveAsDialog.style;
      st.border='1px outset black';
      st.height='200px';
      t.saveAsDialog.innerHTML=" <legend id="+"title"+">Save as</legend>"+
      "<ul>"+
      "<il>"+
      "<input type="+"text"+" "+"id="+"savepath"+" />"+
      "</il>"+
      "</ul> "+
      "<ul>"+
      "<il>"+
       "<input type="+"button"+" "+"id="+"save"+" />"+
      "</il>"+
      "<il>"+
       "<input type="+"button"+" "+"id="+"cancel"+" />"+
      "</il>"+
      "</ul> ";
    } 
  
     t.savePanel.appendChild(t.saveAsDialog);     
     document.body.appendChild(t.savePanel);
     //save path
     t.savePath=document.getElementById("savepath");
     st=t.savePath.style;
     st.width='300px';
     // save button
     t.saveButton=document.getElementById("save");
     t.saveButton.value='Save';
     st=t.saveButton.style;
     st.left='300px';
      __q.EventBoundle.addEvent(t.saveButton,'mousedown',function(){

   t.addSaveEvent(t.savePath.value);
   alert('save success!');
   document.body.removeChild(t.savePanel);
  });
     //cancel button
     t.cancelButton=document.getElementById("cancel");
       t.cancelButton.value='Cancel';
     __q.EventBoundle.addEvent(t.cancelButton,'mousedown',function(){
   document.body.removeChild(t.savePanel);
  });
 },
addSaveEvent:function(path)
{
   var t=this;
  try {
  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
 } catch (e) {
  alert("Permission to save file was denied.");
 }
 t.savefile = path;
  t.file = Components.classes["@mozilla.org/file/local;1"]
  .createInstance(Components.interfaces.nsILocalFile);
 t.file.initWithPath(t.savefile );
 if ( t.file.exists() == false ) {
  alert( "Creating file... " );
  t.file.create( Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 420 );
 }
  t.outputStream = Components.classes["@mozilla.org/network/file-output-stream;1"].createInstance( Components.interfaces.nsIFileOutputStream );
     /* Open flags
 #define PR_RDONLY       0x01
 #define PR_WRONLY       0x02
 #define PR_RDWR         0x04
 #define PR_CREATE_FILE  0x08
 #define PR_APPEND      0x10
 #define PR_TRUNCATE     0x20
 #define PR_SYNC         0x40
 #define PR_EXCL         0x80
 */
 /*
 ** File modes ....
 **
 ** CAVEAT: 'mode' is currently only applicable on UNIX platforms.
 ** The 'mode' argument may be ignored by PR_Open on other platforms.
 **
 **   00400   Read by owner.
 **   00200   Write by owner.
 **   00100   Execute (search if a directory) by owner.
 **   00040   Read by group.
 **   00020   Write by group.
 **   00010   Execute by group.
 **   00004   Read by others.
 **   00002   Write by others
 **   00001   Execute by others.
 **
 */

  t.outputStream.init( t.file, 0x04 | 0x08 | 0x20, 420, 0 );
  t.output = "<html><head><title>"+t.savefile +"</title></head><body>"+document.body.innerHTML+"</body></html>"; 
  t.result = t.outputStream.write( t.output,t.output.length );
     t.outputStream.close();

   }
}

Note:

__qp is a class, and saveMgr is its property,  you can use the function as below:

 

var __q;

__q=new __qp();

 

__q.saveMgr.save();

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值