javascript - Why doesn't this onchange event work? -


if (!localstorage.text) localstorage.text = document.body.innerhtml;  function ifchanged() {     document.body.innerhtml.onchange = function() {         if (document.body.innerhtml !== (localstorage.text)) alert("no match");     }; }  ifchanged(); 

it doesn't check if changed. went wrong?

it's not working because onchange event form fields (it fires when field's value changes). not fired when html changes, just, example, when user types key in textbox.

the best way know when on page changes have code making changes in first place signal change being made (this cleanly done sort of event broadcast).

if want way, use timer periodically polls changes:

setinterval(ifchanged, 1000);    // check once every second (1000ms) 

Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -