angelali
11-04-2012, 07:16 PM
I am making a rich text editor since 3 days.. Everything is fine except two things I want to add now. Of the things is a word count.
Well, I am using an IFrame. When the user will type, I want that simultaneously, the number of words he is typing is displayed. So here is code:
My iframe:
<iframe id="iframe"></iframe>
The paragraph to display the number of words:
<p id="num">0</p>
The function in JavaScript for the word count:
function wordcount () {
var chars = document.getElementById("iframe").contentWindow.document.body.innerHTML.length;
var regex = /\s+/gi;
var words = chars.trim().replace(regex, ' ').split(' ').length;
var answer = document.getElementById("num");
answer.innerHTML = wordcount();
};
Well, I want that each word the user is typing, the number of words is displyed, but it is not working.. Can someone help?
Well, I am using an IFrame. When the user will type, I want that simultaneously, the number of words he is typing is displayed. So here is code:
My iframe:
<iframe id="iframe"></iframe>
The paragraph to display the number of words:
<p id="num">0</p>
The function in JavaScript for the word count:
function wordcount () {
var chars = document.getElementById("iframe").contentWindow.document.body.innerHTML.length;
var regex = /\s+/gi;
var words = chars.trim().replace(regex, ' ').split(' ').length;
var answer = document.getElementById("num");
answer.innerHTML = wordcount();
};
Well, I want that each word the user is typing, the number of words is displyed, but it is not working.. Can someone help?