我希望获得整个文档的长度(如在 str.length 中)以及文档可能使用的任何其他文件。这个问题(How to get the entire document HTML as a string?)很有帮助,但它只给出了当前文档中的字符,没有考虑任何链接的 js 或 css 文件。有什么建议吗?
最佳答案
这完全是伪代码,但它应该对您有所帮助。虽然不可能保证所述长度的准确性 - 由于 HTML 编码的变化量以及页面到页面链接的深度。
这也将使用 Jquery。
var length = 0;
$(document).ready(function() {
//do whatever you need to, to get the current document link (using link provided above)
length = currentDocument.Length;
//iterate through each LINK HREF
//do the same for script and SRC
$(document).find("link").each(function() {
var attr = $(this).attr("href");
//if this accesses a different server than your own, it prolly will fail
if (attr != null)
{
$.ajax({
url: attr,
async: false,
success: function (data){
length += data.length;
}
});
}
});
}
关于Javascript获取文档中的字符,包括css和javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29090636/