skip to Main Content

hello 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.

3

Answers


  1. simple, Change your html like this way

    <a href="#" onclick="linkPopup()" title="popup"> Another Page </a>
    

    Then define you function like this way

    function linkPopup() {
        // do your function task here
        alert("Alert");
    
        // go to the another page
        window.location.href = "another.html";
    }
    
    Login or Signup to reply.
  2. i think you need to call function before goes to another.html , to achieve this , very simple is

    remove link from anchor and location.href in function

    function linkPopup()
    {
       //some code here and last line is below,
       location.href = 'another.html';
    }
    
    Login or Signup to reply.
  3. 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>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search