Script1.js is attached to both MyWebsite1.html and MyWebsite2.html, Script2.js is only attached to MyWebsite2.html. Script1.js is attached first in of MyWebsite2.html.
Script1.js
var global_var;
function open() {
global_var = 1;
window.open("MyWebsite2.html", "_self");
}
Script2.js
$(document).ready(function(){
console.log(global_var);
});
When calling the open() function of my first script (via onclick of MyWebsite1.html) it sets global_var to 1 and opens MyWebsite2.html correctly. But for Script2.js global_var is still undefined.
If I set global_var to 1 outside of the open() function in Script1.js, then for Script2.js global_var is 1.
If you are wondering why I’m using $(document).ready(function(){}: because I want to append html code with it later to MyWebsite2.html.