Rohit Azad Rohit Azad - 4 months ago 8
HTML Question

How to find url parameter # with value in javascript

I need to find url parameter # with value in javascript.

my url is like:


http://rohitazad.com/wealth/tax/how-to-file-your-income-tax-return/newslist/34343443.cms?intenttarget=no&utm_source=newsletter&utm_medium=email&utm_campaign=ETwealth&type=wealth#sid53239948&ncode=23432kjk#%kjimwer


i want to find this value
#sid53239948


I find this How can I get query string values in JavaScript?

but how to find this value in url?

Answer

EDIT:
This will filter the sid into the sid-variable wherever you put your hash.

var url_arr = window.location.hash.split('&'),
    sid = '';

url_arr.filter(function(a, b) {
    var tmp_arr = a.split('#')
    for (var i in tmp_arr)
        if (tmp_arr[i].substring(0, 3) == 'sid')
            sid = tmp_arr[i].substring(3, tmp_arr[i].length)
});

console.log(sid) // Will output '53239948'

Old answer:

var hash_array = window.location.hash.split('#');
hash_array.splice(0, 1);
console.log(hash_array);