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?
-
the function is loaded by ajax - are you loading a function declaration content by ajax?RomanPerekhrest– RomanPerekhrest2016年12月04日 21:35:29 +00:00Commented Dec 4, 2016 at 21:35
-
ajax.php loads a part of code after it calculates a data.passwd– passwd2016年12月04日 21:43:59 +00:00Commented Dec 4, 2016 at 21:43
-
if that content is generated by backend side, then make replacement on backend and let front-end get a prepared contentRomanPerekhrest– RomanPerekhrest2016年12月04日 21:47:23 +00:00Commented Dec 4, 2016 at 21:47
-
But if I have only frontend access? It's a bookmarklet that clicks on popup in a new tab, instead of new window.passwd– passwd2016年12月04日 21:49:23 +00:00Commented Dec 4, 2016 at 21:49
-
let's comprehend things as they are: are you working with some text and just trying to replace one substring to another ?RomanPerekhrest– RomanPerekhrest2016年12月04日 22:05:24 +00:00Commented Dec 4, 2016 at 22:05
1 Answer 1
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.
4 Comments
function.toString() and eval).var ev = window[fnstring]; instead of eval?fnstring.