Removing hash from URL

后端 未结 5 850
忘了有多久
忘了有多久 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:54

    If I understand correctly,

    Some Text
    

    clicking the above link in a browser normally results in an added hash in the address bar, like www.websitename.com#someElementID <- this is what you're looking to prevent, yes?

    The solution I just tested which is working and DOES NOT refresh the page is:

    event.preventDefault();
    

    This works in a 'click()' event that involves anchor tags that link to elements' id's, such as in the anchor tag example above. In action, it would look like this in your 'click()' event:

    
    

    Now, clicking on the same link leaves the address bar with the same URL www.websitename.com, WITHOUT the added hash from clicking the anchor.

提交回复
热议问题