0

I am making web pages using JavaScript. I have two pages, one is index page and about us page. there are several links in index page that direct to about us page, but I want to window.onload function different on about us page when click different link on index page. how to control this?

Below is my codes. when click About us link on index page, open about us page and execute window.contantChange('1'); when click Privacy Policy link on index page, open about us page and execute

window.contantChange('2')

On the index page links are

 <td class="footerTd"><a href="About-Us/About-Us.html">About Us</a></td>
  <td class="footerTd"><a href="About-Us/About-Us.html">Privacy Policy</a></td>

On the About Us page

 <script type="text/javascript">
        window.contantChange('1');
             function contantChange(ID)
        {
                                var ServicesleftBannerItem = document.getElementsByClassName("ServicesleftBannerItem");
                var ServicesleftBannerItema = document.getElementsByClassName("ServicesleftBannerItema");
                var linkArrow = document.getElementsByClassName("linkArrow");

            for (var i = 0; i < ServicesleftBannerItem.length; i++) 
              {
              ServicesleftBannerItem[i].style.background = 'white';
               ServicesleftBannerItem[i].style.borderRight = 'none';
              ServicesleftBannerItem[i].style.borderLeft = 'none';
              ServicesleftBannerItem[i].style.borderBottom = 'none';
              ServicesleftBannerItem[i].style.borderTop = '1px solid rgba(115, 115, 115, .3)';
                 }
            ServicesleftBannerItem[ServicesleftBannerItem.length-1].style.borderBottom = '1px solid rgba(115, 115, 115, .3)';

                        for (var i = 0; i < linkArrow.length; i++) 
              {linkArrow[i].style.color = '#000000';
    }               
                                    for (var i = 0; i < ServicesleftBannerItema.length; i++) 
              {ServicesleftBannerItema[i].style.color = '#000000';
    }
             if (ID==1)
     {
            var ServicesleftBannerItemHiddenCheck1 = document.getElementById('ServicesleftBannerItemHiddenCheck1');
             ServicesleftBannerItemHiddenCheck1.style.background = '#737373';
             ServicesleftBannerItemHiddenCheck1.style.border = '1px solid rgba(0,0,0, 0.5)';
              document.getElementById('ServicesleftBannerItemHiddenCheckA1').style.color = 'white';
              document.getElementById('ServicesleftBannerItemHiddenCheckB1').style.color = 'white';
              document.getElementById("ServicesRight").innerHTML = "About Us";
             }
                     if (ID==2)
     {
            var ServicesleftBannerItemHiddenCheck2 = document.getElementById('ServicesleftBannerItemHiddenCheck2');
             ServicesleftBannerItemHiddenCheck2.style.background = '#737373';
             ServicesleftBannerItemHiddenCheck2.style.border = '1px solid rgba(0,0,0, 0.5)';
              document.getElementById('ServicesleftBannerItemHiddenCheckA2').style.color = 'white';
              document.getElementById('ServicesleftBannerItemHiddenCheckB2').style.color = 'white';
              document.getElementById("ServicesRight").innerHTML = "Privacy Policy";

     }
                }
                  </script> 
  • Possible duplicate of [How do I get the referrer in Javascript?](http://stackoverflow.com/questions/6856697/can-i-get-the-referrer#6856725), i.e. if you want it to do something different when a link on `index` is used. – Luke Briggs Nov 29 '16 at 18:15
  • 2
    Post some code. – Mitya Nov 29 '16 at 18:15
  • Just add an "onload" on index, and another one on "about_us" ;-) Or.. Provide us a sample as required by Utkanos! – Nico Nov 29 '16 at 18:17
  • @Utkanos provided as your request. could you please answer now? –  Nov 29 '16 at 18:32
  • @Nico Your answer not what I want. thanks. I added some codes. –  Nov 29 '16 at 18:32
  • 1
    There's at least 3 approaches; This kind of thing is usually done server side though which would be a completely different answer to this question. Other two: Use document.referrer, use location.hash. Which is actually suitable depends on a range of things. – Luke Briggs Nov 29 '16 at 18:39
  • @Nico `window.onload` only works for one function, the last one overrides the previous function calls. – zer00ne Nov 29 '16 at 18:39
  • @Nico I do not think you carefully read my post. every time only one function, but when click different link execute different function. –  Nov 29 '16 at 18:43
  • @LukeBriggs Thank you. I will research about document.referrer, use location.hash. –  Nov 29 '16 at 18:44
  • You change everything in your message, how can I answer you in this conditions? Your original message was, simple, so my answer was. – Nico Nov 29 '16 at 18:53
  • @LukeBriggs I solved. Used hash. thank you man. –  Nov 29 '16 at 19:28

0 Answers0