Using a variable from a different window - Javascript Browser Object Model

Javascript examples for Browser Object Model:Window opener

Description

Using a variable from a different window

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <script>
function ShowData()/*from  w  w w. java2 s. c o m*/
{
    display("NewWindowData: " + this.NewWindowData);
    display("MainWindowData: " + window.opener.MainWindowData);
}
function display(msg) {
    var p = document.createElement('p');
    p.innerHTML = String(msg);
    document.body.appendChild(p)
}

      </script> 
   </head> 
   <body> 
      <input type="button" value="Show Data" onclick="ShowData()">  
   </body>
</html>

Related Tutorials