Search code examples
javascripthtmljquerycss

How to call function after clicking href to another link loaded


I need some function going to run after a link before another page.

for example.

this is main.html

<div>
<a href="another.html" onclick="linkPopup()" target="_blank" title="popup"></a>
</div>

and when click tag.

another.html loaded and open popup inside in function exist already in another.html

another.html open popup!

like this.


Solution

  • Use localStorage for this functionality. https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage

    Page current.html

    <a href="javascript:;" onclick="linkPopup()" title="popup"> Another Page </a>
    <script>
      function linkPopup(){
        localStorage.setItem('popup',true)
        window.location.href = "another.html";
      }
    </script>
    

    Page another.html

    <script>
      document.addEventListener('DOMContentReady',function(){
        if(localStorage.getItem('popup')==true){
         // Script for open the popup
        }
      })
    </script>