Removing hash from URL

后端 未结 5 875
忘了有多久
忘了有多久 2021-01-01 05:09

After removing hash from URL using window.location.hash=\'\' page getting reloaded in firefox.

EDIT

Example:

wwww

5条回答
  •  长情又很酷
    2021-01-01 05:55

    you will find this example from w3schools very useful for your need plus it gives you elegant scrolling move compatable with all browsers, check below code :

      // Add smooth scrolling to all links
      $("a").on('click', function(event) {
    
    // Make sure this.hash has a value before overriding default behavior
    if (this.hash !== "") {
    
        // Prevent default anchor click behavior
        event.preventDefault();
    
        // Store hash
        var hash = this.hash;
    
        // Using jQuery's animate() method to add smooth page scroll
        // The optional number (800) specifies the number of milliseconds it takes to scroll to the specified area
    
          $('html, body').animate({
              scrollTop: $(hash).offset().top
           }, 800, function(){
    
          // Add hash (#) to URL when done scrolling (default click behavior)
          // obvously you will ignore this step because you want to remove the hash in first place - but just in case you want turn it on again
    
          window.location.hash = hash;
        });
       } // End if
      });
    });
    

提交回复
热议问题