title: Go back one page and scroll to div ID
body: <p>First off thanks for taking the time to read my question. I'm trying to make a normal link (href), link back one page and scroll to an div <code>id</code>. I've been looking at this question: <a href="https://stackoverflow.com/questions/30518747/redirect-to-a-div-on-a-different-page-with-smooth-scrolling">Here</a>. Which does exactly what I want. So I've linked the JavaScript file in my header and placed the jQuery code in my footer. But it does nothing.</p>
  
  <p>This is my link:</p>
  
  <pre><code>&lt;div class="col-xs-4 text-center"&gt;
      &lt;a href="/the_liked_page/" data-id="my_id" class="gobackandscroll"&gt;&lt;i class="fa fa-th-large fa-2x" aria-hidden="true"&gt;&lt;/i&gt;&lt;br&gt;Go back&lt;/a&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Nothing fancy... and here is the script:</p>
  
  <pre><code>// Read the cookie and if it's defined scroll to id
  var scroll = jQuery.cookie('scroll');
  if(scroll){
      scrollToID(scroll, 1000);
      jQuery.removeCookie('scroll');
  }
  
  // Handle event onclick, setting the cookie when the href != #
  jQuery('.gobackandscroll').click(function (e) {
      e.preventDefault();
      var id = jQuery(this).data('id');
      var href = jQuery(this).attr('href');
      if(href === '#'){
          scrollToID(id, 1000);
      }else{
          jQuery.cookie('scroll', id);
          window.location.href = href;
      }
  });
  
  // scrollToID function
  function scrollToID(id, speed) {
      var offSet = 65;
      var obj = jQuery('#' + id).offset();
      var targetOffset = obj.top - offSet;
      jQuery('html,body').animate({ scrollTop: targetOffset }, speed);
  };
  </code></pre>
  
  <p>I don't get any errors in my console.log and it links to the page I want. But there is no scrolling.</p>
  
  <p>When I delete all the data and mark up both pages like this:
  <a href="http://plnkr.co/edit/l2aassM4biyNRWNCrvUz?p=preview" rel="nofollow noreferrer">http://plnkr.co/edit/l2aassM4biyNRWNCrvUz?p=preview</a> it does work. So the JavaScript is correctly loaded and storing the cookie.</p>
  
  <p>So I thought maybe the data-id is not stored so I've put an alert on the click using: </p>
  
  <pre><code>alert(id);
  </code></pre>
  
  <p>This gives the correct <code>data-id</code> but this doesn't scroll on the next page. Does anyone have an idea why this isn't working or a better suggestion for this? Thanks of the help...</p>