Advertisement
DidouS

return to page internal ID on history.back();

Apr 1st, 2019
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  use:
  3.  
  4.  javascript:hJump( 'yourrowid' , 'https://www.yourdomain.com/yourlink' );
  5.  
  6.  as the link target/href
  7.  
  8. */
  9.  
  10. function hJump( id , link ) {
  11.     if ( history.pushState ) {
  12.  
  13.         let newurl = window.location.protocol + "//" + window.location.host + window.location.pathname + ( window.location.search ? window.location.search : '' ) + '#' + id  ;
  14.         window.history.pushState({path:newurl},'',newurl);
  15.     }
  16.     window.location.href =  link ;
  17.    
  18. }
  19.  
  20. jQuery( "#results a" ).click( function( event ){
  21.  
  22.     // prevent from going to the link before we want it to
  23.     event.preventDefault();
  24.     // reference the dom-element
  25.     $this = jQuery( this );
  26.     // set history and jump away!
  27.     hJump( 'result', $this.attr('href') );
  28. } );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement