使用javascript计算网页中的字数

使用javascript计算网页中的字数,javascript,Javascript,假设我打开了一页。我正在使用firefox并安装了firebug。如何使用firebug控制台中运行的javascript查找此网页中的字数。试试这个 document.body.innerText.split(' ').length 对于Firefox,您可以使用(Firefox使用该属性。) 如果你想去掉空白空间和换行符 document.body.innerText.split(/\s/).filter(function (txt) {return /\S/.test(txt)}).le

假设我打开了一页。我正在使用firefox并安装了firebug。如何使用firebug控制台中运行的javascript查找此网页中的字数。

试试这个

document.body.innerText.split(' ').length
对于Firefox,您可以使用(Firefox使用该属性。)


如果你想去掉空白空间和换行符

document.body.innerText.split(/\s/).filter(function (txt) {return /\S/.test(txt)}).length;
你可以使用

document.body.innerText.split(/\s/).filter(function (txt) {return /\S/.test(txt)});

在firefox上,使用
document.body.innerText
use
document.body.textContent

代替
document.body.innerText,我尝试了这个方法,但是它显示了“document.body.innerText是未定义的”firefox添加的等效属性:注意,虽然textContent获取所有元素的内容,包括和元素,但大部分等效的IE特定属性innerText,不:请注意,虽然textContent获取所有元素的内容,包括和元素,但大部分等效的IE特定属性innerText没有尝试我提供的链接。我打开“”页面,打开firebug控制台,运行命令“document.body.innerText.split(/\s/).filter(function(txt){return/\s/.test(txt)}).length;”它说TypeError:document.body.innerText未定义
document.body.innerText.split(/\s/).filter(function (txt) {return /\S/.test(txt)});