Re: [問題] 如何取得整頁目前的所有 HTML?

看板Ajax作者 (for pete's sake)時間15年前 (2009/06/11 02:17), 編輯推噓3(304)
留言7則, 3人參與, 最新討論串2/2 (看更多)
※ 引述《danny0838 (道可道非常道)》之銘言: : 如題,在下想製作一個文字處理程式,把網頁中的一些 tag 內容做處理後輸出, : 為了方便起見,想輸出原始碼,簡單範例如下: : function convert() { : var d = documet.getElementsByTagName('SPAN'), i=d.length; : while(i--) { : if (d[i].className=='test') { : d[i].innerHTML += 'test'; : d[i].style.fontSize = '1.5em'; : } : } : // 輸出本頁被轉換後的原始碼為純文字,但要如何取? : var s = '<PRE>' + 本頁被轉換後的原始碼 + '</PRE>'; : document.open(); : document.write(s); : document.close(); : } var s = document.getElementsByTagName("html")[0].innerHTML; 這個範例我寫好了,以下demo供參考。 http://noking.googlepages.com/convert.html -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 122.116.40.183

06/11 09:46, , 1F
謝謝 但<!doctype...和<html xmlns=...無法取到嗎?
06/11 09:46, 1F

06/11 10:20, , 2F
IE可再利用outerHTML取得多一點 其他瀏覽器也有解 但比較
06/11 10:20, 2F

06/11 10:21, , 3F
麻煩 自己google "outerHTML firefox"
06/11 10:21, 3F

06/11 21:16, , 4F
既然這是ajax板,那直接從server去抓人網頁應該就可以
06/11 21:16, 4F

06/11 21:16, , 5F
符合你的需求了XD
06/11 21:16, 5F

06/12 00:27, , 6F
有想過,但抓完要處理呀...而我舉的例子用replace很難搞
06/12 00:27, 6F

06/12 00:28, , 7F
但用node去處理就簡單很多
06/12 00:28, 7F
文章代碼(AID): #1AB_YbrG (Ajax)
文章代碼(AID): #1AB_YbrG (Ajax)