The website uses onLoad to load a JavaScript file (.js).
I want to change one of the functions inside that js file using JavaScript.
The function is called “Hello13” and is among many other functions (hello5, hello6, etc..)
The Hello13 function looks something like this:
function hello13(x, y, z) {
if (x == null) {
//something, something.
}
if (y == null) {
//something else, something else.
}
if (z == null) {
//something diffrent, something diffrent.
}
}
So as you can see, when the function is called it is given some values (x, y, z).
I want to “hard code” the z to be my own value (inside the js file).
So it would be something like this after i have Programmatically changed it:
function hello13(x, y, z) {
z = MyValueOverride.
.....
How can i add my own “z” value inside the js file, After the site has loaded, using JavaScript?
If it’s a globally defined function in some javascript that is loaded via an inline script tag (either locally defined or in an external JS file), you can just redefine it with your own version of that function. Whichever definition comes last will be the active one.
So, it sounds like what you want to do is to provide your own definition right after the external JS file containing the target function. That way your definition will replace the original one. If you want to retain the original one, you can assign it to another variable name before replacing it.
If the external javascript file is dynamically loaded, then things are a little more complicated because you will need to figure out how to know when the dynamically loaded external JS file has been loaded so you can then define your override. You’d have to show us more about how the external JS file is loaded for us to offer specifics on how to do that.