rakeshr

firefox anchor fix

Sep 2nd, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script>
  2. /*location.hash returns the anchor part of an URL as a string,
  3. with hash (#) symbol included. */
  4. //wait for page elements to load
  5. //execute function only if the anchor exists in the URL address
  6. window.onload = function() {if(location.hash){
  7.     //remove # from the string
  8.     var elId = location.hash.replace('#','');
  9.     //locate the anchored element on the page by its ID property
  10.     var scrollToEl = document.getElementById(elId);
  11.     //scroll to the anchored element
  12.     scrollToEl.scrollIntoView(true);  
  13. }
  14.  }
  15. </script>
Add Comment
Please, Sign In to add comment