Skip to content

Instantly share code, notes, and snippets.

@mcnaveen
Last active September 3, 2024 04:50
Show Gist options
  • Save mcnaveen/e64295738d52bed402ab6d7c67798ede to your computer and use it in GitHub Desktop.
Save mcnaveen/e64295738d52bed402ab6d7c67798ede to your computer and use it in GitHub Desktop.
Scroll into View after the page load in Safari
// This function ensures the current browser is Safari
// Checks if the URL has a jumplink
// If the webpage has lots of heavy images before the target section. It’s good idea to cache them with CDN or Rocketloader
window.addEventListener('load', function() {
const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
if (isSafari && window.location.hash) {
const element = document.querySelector(window.location.hash);
if (element) {
element.scrollIntoView();
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment