I have the following code to replace all instances of “onAppDeactivate” with “onAppActivate” in the entire body of the document, but it doesn’t seem to be working at all. Any ideas?
var pageSource = document.body.getElementsByTagName("script");
var replaceWithThis = "onAppActivate";
for(var i=0, l=pageSource.length; i<l; i++)
{
pageSource[i].innerHTML.replace(/onAppDeactivate/gi, replaceWithThis)
}
You can’t replace text in a script file or script block that has already been parsed. It won’t do anything.
You can replace entire functions in your javascript by actually assigning new code to the function name in javascript (not with text manipulation).
For example, if there was a function already defined:
You, could replace that with your own function:
In your pastebin code, you can disable the onBlur() and onFocus() global functions by running this code after the original code in the page runs.