0

index.php (Home page):

<a class="whitelink" href="about.php" onclick="redirectcontact()">Contact Us</a>
<a class="whitelink" href="about.php" onclick="redirectfaq()">FAQ</a>

About.php (About Us Page) : Basically for this, my function redirectfaq() does not work but my redirectcontact() function works so how do I make them both work as in redirecting and executing click function after clicking the links on home page

 function redirectcontact()
        {
             
          window.localStorage.setItem('click',true);
        }
function redirectfaq()
        {
             
          window.localStorage.setItem('click2',true);
        }
        
        window.addEventListener('DOMContentLoaded',function(){
           
              
             if(window.localStorage.getItem('click')) {
                    window.localStorage.removeItem('click');
                    document.getElementById("clickcontact").click();
              }
 if(window.localStorage.getItem('click2')) {
                    window.localStorage.removeItem('click2');
                    document.getElementById("clickfaq").click();
              }
        });
raphael
  • 5
  • 3
  • 1
    1) You need to store before changing location 2) localStorage only stores strings. – Markus Zeller Aug 03 '20 at 14:16
  • You shouldn't put code after `window.location = "..."`, try setting the localstorage item first. – Jannes Carpentier Aug 03 '20 at 14:18
  • see [this stackoverflow answer](https://stackoverflow.com/questions/10525584/what-happens-to-code-after-a-javascript-redirect-setting-window-location-href) – Jannes Carpentier Aug 03 '20 at 14:18
  • You are breaking default anchor behavior by redirecting via JavaScript instead of the `href` attribute. For users who often use their middle mouse button to open pages in new tabs, that is really frustrating. – Ivar Aug 03 '20 at 14:23
  • ok I have changed it to use href and tried the code but whenever i click away from the about page, it just redirects me back to the about page indefinitely – raphael Aug 03 '20 at 14:41

0 Answers0