Search code examples
javascripturlfragment-identifier

How to read the #hash (or fragment identifier) of the current page URL?


If I am on https://www.website.com/#something, how can I return the hash value "something" from the URL?


Solution

  • window.location.hash its that simple.

    donot use all those methods which consume CPU and effects performance.

    If DOM provides something predefined use it first.

    To pass value to PHP please do and ajax call to php.

    var hash = window.location.hash;
    
    $.ajax({
        url: 'someurl.php',
        data: {hash: hash},
        success: function(){}
    })