標籤: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> "+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儲存訪問