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?
好吧,我不用js来知道,但是有办法用它来获取页面的真正源代码吗?
document.body.innerHTML for example gives some kind of "fixed up" version where malformed tags have been removed.
document.body。例如,innerHTML提供了某种“固定”版本,在其中删除格式错误的标记。
I'm guessing using XMLHttpRequest on the original page might work, but seems kind of stupid.
我猜在原始页面上使用XMLHttpRequest可能会有用,但似乎有点愚蠢。
3 个解决方案
#1
4
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.
这是因为浏览器解析DOM而不将HTML保存在内存中。返回给您的是浏览器将当前DOM转换回HTML,这是大写标记的原因,并且在适用的情况下缺乏自关闭标记。
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.
XMLHttpRequest是最好的方式。在大多数情况下,假设服务器没有发送无缓存头,HTML页面已经完成下载,XMLHttpRequest几乎是即时的,因为文件是从缓存中获取的。
#2
3
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).
对于访问同源的JS, XMLHttpRequest是很好的。您可以使用这种技术访问任何“原始”格式的JS文档,而无需浏览器阻止(例如,转换到DOM并返回)。
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.
我不确定我是否理解您的评论re: XMLHttpRequest是愚蠢的:是因为您担心工作的潜在复制吗?即从源服务器获取代码2次。
#3
2
I typically use FireBug when I want to peruse or copy source files.
当我想要仔细阅读或复制源文件时,我通常使用FireBug。
#1
4
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.
这是因为浏览器解析DOM而不将HTML保存在内存中。返回给您的是浏览器将当前DOM转换回HTML,这是大写标记的原因,并且在适用的情况下缺乏自关闭标记。
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.
XMLHttpRequest是最好的方式。在大多数情况下,假设服务器没有发送无缓存头,HTML页面已经完成下载,XMLHttpRequest几乎是即时的,因为文件是从缓存中获取的。
#2
3
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).
对于访问同源的JS, XMLHttpRequest是很好的。您可以使用这种技术访问任何“原始”格式的JS文档,而无需浏览器阻止(例如,转换到DOM并返回)。
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.
我不确定我是否理解您的评论re: XMLHttpRequest是愚蠢的:是因为您担心工作的潜在复制吗?即从源服务器获取代码2次。
#3
2
I typically use FireBug when I want to peruse or copy source files.
当我想要仔细阅读或复制源文件时,我通常使用FireBug。