Search code examples
javascriptjquerypopupparent

javascript/jquery - Hide element in parent tab controlled from pop up window part 2


Can somebody help me with this? I have a parent window and a pop up window. I want them to communicate, but there is something wrong with the code. please advise me for javascript or jquery. I just want the popup to control the parent window too.

My index.html

<html>
<head>
<script>
function openwindow() { window.open("pop.html","mywindow","menubar=1,resizable=1,width=400,height=400"); }
</script>
</head>
<body>
<a href="href="javascript: openwindow()"" id="will-hide-in-pop">Show pop up!</a>
</body>
</html>

then after we click the anchor , pop will show. here is the pop up code with form: popup code:

<html>
<head>
<script>
function clicked(){window.opener.document.getElementById('will-hide-in-pop').style.display="none"; }
</script>
</head>
<body>
<div>
<form action="process.php" method="GET">
<input type="text" name="text" />
<input type="checkbox" name="cbox" />
<input type="submit" name="" onclick="clicked()"/>
</form>
</div>
</body>
</html>

did I put a right code? I just want it if the form is submitted, the anchor in the parent window will also vanish

please help me


Solution

  • Try invoking your function in jQuery submit:

     $(document).ready(function () {
         $('form').submit(function () {
             clicked();             
          });       
     });