3

There are several elements on HTML page which triggers a js function HardCoded(). I cannot modify HardCoded() function.

I want to run some custom js code after the HardCoded() function is getting called. How can I do that? Is there any handlers for js functions?

I'm building a chrome extension that's why I cannot modify page source code.
I have access to JQuery.

One way is to find all elements who are calling HardCoded() and attach events to those elements but I would like to avoid this method.

GorvGoyl
  • 42,508
  • 29
  • 229
  • 225

1 Answers1

5

You could do something like this:

var oldFn = HardCoded;
window.HardCoded = function(){
   var res = oldFn.apply(this, arguments);
   // New Code ....
   return res;
}

What this does is to create a reference to the HardCoded function, redefine this function and then call the old implementation using the previously created reference.

Titus
  • 22,031
  • 1
  • 23
  • 33