當(dāng)前位置:軟件學(xué)堂 > 資訊首頁 > 網(wǎng)絡(luò)編程 > 編程其他 > JS代碼實現(xiàn)自動保存網(wǎng)頁的文本

JS代碼實現(xiàn)自動保存網(wǎng)頁的文本

2012/10/22 19:46:54作者:佚名來源:網(wǎng)絡(luò)

移動端

【實例名稱】

自動保存網(wǎng)頁的文本

【實例描述】

 為了保存網(wǎng)頁的一些內(nèi)容,需要調(diào)用另存為對話框,實現(xiàn)內(nèi)容的保存。本例演示如何快速保存網(wǎng)頁的內(nèi)容。

【實例代碼】

 <html xmlns="http://www.w3.org/1999/xhtml" > <head> <title>標(biāo)題頁</title> <script> window.onload=function() {      document.open("text/html");                    //打開窗口      document.write("把這些文字保存起來?。。。。?quot;);//輸出內(nèi)容      document.execCommand("saveAs","true","我的網(wǎng)頁");//打開另存為對話框      document.close();                                //關(guān)閉文檔 } </script> </head> <body> </body> </html>

【運(yùn)行效果】

運(yùn)行效果

【難點剖析】

本例的重點是“execCommand”方法。此方法用來執(zhí)行瀏覽器中的一些常用操作,本例中使用“saveAs”調(diào)用“另存為”對話框,將網(wǎng)頁的內(nèi)容進(jìn)行保存。

【源碼下載】

本實例JS代碼下載

 

標(biāo)簽: JS代碼  文本