0

I Have 2 JavaScript file, and I'm trying to log the "global" variable in the 2nd JavaScript file after I assign a value to the variable in the 1st js file. In the first js file I want to open a new window (another .html file) with the variable that's log-d

main.js: (1st)

var apple;
document.getElementById("next").addEventListener("click", function(){
    apple = "apple ";
    console.log(apple ); //log: apple

    window.open("second.html", "_top");
});

2nd.js:

function test(){
$(document).ready(function(){
    console.log(apple); //log: undefined

});
k.peter
  • 3
  • 1
  • You have two separate _documents_, the global scope doesn't cover multiple documents, every document has its own global scope. – Teemu Dec 20 '18 at 19:16

1 Answers1

0

Try window.GlobalVar = 'apple' or window[DynamicVar] = apple

If you make an extension, check this.

Vadim
  • 306
  • 1
  • 5
  • 13