Is it possible to pass variables between two different JS files without using Node js, only with vanilla JS? I am only doing this on client side, I am not using a server or anything else.
In the first file (first.js) I have this (shortened) bit of code:
function appendImg(){
var img = document.createElement('img');
img.src = tempImg.src;
document.body.appendChild(img);
createImg(index++);
img.onclick = function(event){
window.location.href = "second.html";
}
}
Where "img" comes from a series of operations, src assigning, etc, from a given images array I wrote at the beginning of my file.
What I'm trying to do is, when I click a certain image, it redirects me to another HTML page, as you can see, where I would like to display the same image that was clicked.
I'm having trouble doing this, as my img variable is declared in a function, and the second JS file does not recognize it.
How could I change this?