js 將網頁產生為html儲存訪問

來源:互聯網
上載者:User

標籤:style   io   color   ar   os   使用   java   sp   strong   

2012-04-03今天實現了一個需求,主題是將瀏覽中的網頁產生html儲存起來,記錄訪問url,掛在公司網站上做案例。  首先忙活了N久的是去搜尋產生html的js函數。 什麼IE內建的ActiveX,js外掛程式,js的winow.print();函數調用印表機列印頁面等 最後結果是怎麼搞都是不行。 就快到窮途末路時,在stackoverflow.com網站看到一條問題,也是與產生html相關的。 牛人解決方案如下: 使用jQuery // 看到這句我頓時啞語了,這麼簡單的方法我怎麼想不到 var dom = $("html").html();//擷取html節點的內容//alert(dom); $.post("exportCase.do",{dom:$("html").html()});//伺服器接受請求處理,將html內容輸出為xxx.htm儲存到你想指定的路徑     最後我借鑒與此,寫了一個完善的js函數:<script type="text/javascript"><!--function exportCase(){      try{            var filename = prompt("請輸入要產生的html檔案名稱:","");            if(undefined==filename || ""==filename){                  new Boxy("<div style=‘width:300px;height:100px;‘><p>檔案名稱為空白,產生失敗</p></div>", {title : ‘訊息提示‘});                  return;            }            //alert("export filename:"+filename);            $j.ajax({                  type : "post",                  url : "exportCaseAjax.do",                  cache : "false",                  data : {                        "dom":$j("html").html(),                        "filename":filename,                        "rnd": ajaxRandom()                  },                  dataType:"json",                  success : function(data, textStatus) {                        if(!isUndefined(data)){                              var code = data.code;                              //alert(code);                              if(code==0){                                    var d = data.data;                                    new Boxy("<div style=‘width:400px;height:100px;‘><p>"+d.name+"檔案產生成功!</p><p>訪問路徑為:</p><p>&nbsp;&nbsp;"+d.url+"</p></div>", {title : ‘訊息提示‘});                              } else {                                    new Boxy("<div style=‘width:300px;height:100px;‘><p>"+data.data+"</p></div>", {title : ‘訊息提示‘});                              }                        }                  }            });         }catch(err){}     }//--></script>  伺服器處理的action代碼我就不貼出來了,用I/O就行了。

js 將網頁產生為html儲存訪問

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.