Im looking to inject a variable into a page before a method is run. The situation is as follow
CUSTOM JS CAN GO HERE
my.var = 'cake';
my.function();
I dont have access to be able to modify the page directly, however there is a content area at the top of the page I can add some JS if i need to. Basically i need to overwrite the my.var variable with something else before my.function() is run. Is there a way to do this? (the site is running jQuery 1.4.2.
Thanks
Dan
This is, of course, if
myormy.functionisn’t overwritten by the code you can’t modify directly before the call tomy.function(asmy.varis).For example, in the following scenario:
what you want is impossible (unless you’re able to redefine
somethingor something in it in the same way).Basically, in this case the only thing you could do is to write (let’s assume
somethingisfunction () { alert(my.var) })Well, you’ve got an idea.
Injecting some code in between
my.var = 'cake';andmy.function();is, from the other side, imposible. Roughly speaking, you can choose between two options, whether your code will be executed beforemy.var = 'cake';or aftermy.function();. Executing your code aftremy.var = 'cake';but beforemy.function();is impossible (if we’re speaking of a production environment; of course you could do anything by hands using the debugger, if you need to modifymy.varfor a debugging purpose).