Script link formatting for cross-browser compatibility

228 Views Asked by At

I'm referencing the following scripts in the header of https://livingibogaine.squarespace.com. I'd post the HTML separately, but it's mountainous.

The scripts trigger great in Safari! Firefox and Chrome don't read them at all. Am I formatting them incorrectly? Or this likely a bug in the Squarespace platform?

<link rel="stylesheet" type="text/css" href="http://www.wlvrtn.com/sites/www.livingcleanibogaine.com/css/style-five.css" />

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

<script type="text/javascript" src="http://www.wlvrtn.com/sites/www.livingcleanibogaine.com/js/jquery.sticky.js"></script>

<script type="text/javascript">
    $(window).load(function(){
      $("#page-nav").sticky({ topSpacing: 0 });
    });
</script> 

<script type="text/javascript">
$(function() {
  $('a[href*=#]:not([href=#])').click(function() {
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {

      var target = $(this.hash);
      target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
      if (target.length) {
        $('html,body').animate({
          scrollTop: target.offset().top
        }, 800);
        return false;
      }
    }
  });
});
</script>
2

There are 2 best solutions below

2
On BEST ANSWER

This is possibly because you are loading the page over https, but your scripts over http. Chrome can be a bit fussy about doing insecure things like that. Try changing the jQuery link to src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" and access your jquery.sticky.js file from an https site also.

EDIT: jquery.sticky.js is hosted on a https CDN here - https://cdn.jsdelivr.net/jquery.sticky/1.0.0/jquery.sticky.min.js

0
On

Try using the following code:

<script type="text/javascript">
    jQuery(window).load(function($){
      $("#page-nav").sticky({ topSpacing: 0 });
    });
</script> 

<script type="text/javascript">
jQuery(function($) {
  $('a[href*=#]:not([href=#])').click(function() {
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {

      var target = $(this.hash);
      target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
      if (target.length) {
        $('html,body').animate({
          scrollTop: target.offset().top
        }, 800);
        return false;
      }
    }
  });
});
</script>

See also @JoshLowry answer