Skip to content
Advertisement

How to transfer class value from popup window to parent window using jquery

I want to get class name from popup window to parent window. If my popup window show instagram page and I click on follow button, then the class of the follow button will change. I want if I click on the follow button after that in my parent window count the follow by +1 point. If I don’t click the follow button and close the popup window, then follow won’t count to my parent window.

Can someone give the solution for this problem with some of jquery code?

Advertisement

Answer

Main :

<html lang="en">
    <body>
    <span id="followerCount"></span>
    <br/>
    <button onclick="openPopup()">Open Popup</button>
    </body>
    <script type="text/javascript">
      let followerCount = 999;

      writeFollowerCount();

      function writeFollowerCount() {
        document.getElementById('followerCount').innerText = followerCount.toString();
      }

      function openPopup() {
        window.open('popup.html', 'mypopup', 'width=500,height=300');
      }

      function follow() {
        followerCount++;
        writeFollowerCount();
      }
    </script>
    </html>

Popup :

<html lang="en">
<body>
<button onclick="follow()">Follow</button>
</body>
<script type="text/javascript">
  function follow() {
    window.opener.follow();
    window.close();
  }
</script>
</html>
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement