passwd
passwd

Reputation: 3353

Javascript replace code of function

I am making a bookmarklet and need to change some code inside a page. For example, after page loaded it creates a function which is used 'onclick'. I need to replace a code inside a variable of this function. For example here is a function:

function openNewWindow(){
    newWindow = window.open('http://www.example.org','params','width=200,height=200,resizable=0');

And I need to change this code into this:

function openNewWindow(){
    newWindow = window.open('http://www.example.org','params','_blank');

How can I do it, taking in account, that the function is loaded by ajax?

Upvotes: 0

Views: 753

Answers (1)

devilfart
devilfart

Reputation: 347

Functions can be overwritting by being asigned a new refrence, if you only have access to the front end of the code after the fact. You can replace openNewWindow with a new function;

openNewWindow = function () {
    newWindow = window.open('http://www.example.org','params','_blank'); 
}

However replacing functions that come from third parties are not recomended in a lot of cases because it can produce unexpected results.

Upvotes: 1

Related Questions