Question

I was wondering if it's possible to get text which was changed by JavaScript as a String.

For example you got a site with the text Hello, World and you changed the text with JavaScript into New Text!. Is it possible now to get that the changed text into a String.

I want to find text which was changed with JavaScript like the search function (ctrl+f) but it doesn't works with such code:

  if(document.body.textContent.indexOf("New Text") !== -1){
     return true; 
  }else{
     return true; 
  }

Since I can use the indexOf() function to search a String I thought maybe I can get the changed text somehow as a String.

I appreciate any help! Thanks!

No correct solution

OTHER TIPS

The code below may be useful using jquery.
Be careful it's not thread safe. To make it thread safe you could use an Array, add the changed elements in, and process the elements using an indexer that you can increment when you process for the changed elements ends. So, the indexer not always will point to the last element (it's only an idea).

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <script language="javascript" type="text/jscript">

        // set the function OnChanged for the change event
        $('*').change(OnChanged); 
        // global var
        var previousText = '';


        function doSomeChange(idElement) {
            // Save the prev text. Be careful global var is not the best way to do it
            // When another process could access it the correct value could have been changed
            previousText = $(idElement).text();
            // chage the text
            $(idElement).text('this text is changed using javascript');
            // raise event change
            $(idElement).change();
        }

        //this function will be called when change event of any element will be raised
        function OnChanged() {
            alert('Text changed, text was ' + previousText);
        }  

    </script>
    <title></title>
</head>
<body>
    <p id="TestP">Hello, this is dummy text
        <a href="javascript:doSomeChange('#TestP')">Do change</a></p>
</body>
</html>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top