Javascript, access to variables of other window

Viewed 68

I have to make a web page with two different window and let they share some variables.

When the main window is loaded, the second windows is opened, and here I can store the second window object and access its vars:

Main window

var mainvar=1;
var secondwindow=open('second.htm');
$("button").click(function(){
    alert(secondwindow.testvar);
});

My trouble starts when I want to do the oppsite: access main window vars from the second window script:

Second window

var secondvar=2;
var mainwindow;// how can I set this?
$("bunno").click(function(){
   alert(mainwindow.testvar);
});
2 Answers
Related