0

First of all, I'm a rookie on JavaScript. I'm trying to pass a value taken in an input text from a parent window to its child when you press a button on the parent one. On the parent you have an input where you write a number and a button which opens the new window. On the child window you have 2 buttons: the first one moves the child window to the left the window x pixels (x is the value you insert on the input from parent) and the second one moves the child window to the write x pixels. So when you press the button on the parent page you pass the pixels value info to its child window.

After some hours looking for some information, I did this code:

Parent:

<html>
<head>
</head>
<body>
    <form>
        <input type="text" name="text" id="valor"></input>
        <input type="button" value="open window" onClick="openWindow()">
    </form>

    <script>
        function openWindow() {
            window = window.open('child.html', 'window', 'width=600,height=300');
            value = window.document.getElementById("value");          
            value.innerHTML = document.getElementById("value").value;
        }
    </script>
</body>
</html>

Child:

<html>
<head>
</head>
<body>
    <form>
        <input type="button" value="Left" onClick="moveToLeft()">
        <input type="button" value="Right" onClick="moveToRight()">        
    </form>
    <script>              
        function moveToLeft() {
            window = self.moveTo(-value,0);
        }
        function moveToRight() {
            window = self.moveTo(value,0);        
        }
    </script>
</body>
</html>
Sebastian Richner
  • 782
  • 1
  • 13
  • 21
Beon
  • 1
  • 1

1 Answers1

0

In the parent window declare a global variable and set some value offsetValue = 200.

And then from the child window, you can access it using window.opener.offsetValue