开发者

Getting real source code with javascript?

OK I don't use js enough to know, but is there a way to get the 开发者_开发技巧real source code of the page with it?

document.body.innerHTML for example gives some kind of "fixed up" version where malformed tags have been removed.

I'm guessing using XMLHttpRequest on the original page might work, but seems kind of stupid.


This happens because browsers parse the DOM and don't keep the HTML in memory. What is returned to you is the browser's conversion of the current DOM back to HTML, which is the reason for the uppercase tags and lack of self closing tags where applicable.

An XMLHttpRequest would be the best way to go. In most cases, assuming the server doesn't send the no-cache header, and the HTML page has finished downloading, the XMLHttpRequest would be almost instant because the file is fetched from the cache.


For accessing JS of the same origin, XMLHttpRequest is quite fine. You can have access to any JS document in "raw" format using this technique without the browser getting in the way (i.e. conversion to DOM and back).

I am not sure I understand your comment re: XMLHttpRequest being stupid : is it because you are worried about the potential duplication of work? i.e. getting the code 2times from the origin server.


I typically use FireBug when I want to peruse or copy source files.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜