Vikash Vikash - 1 year ago 96
jQuery Question

How to get query and hash from url using javascript?

I have a url

I want to get
in two variable

for Example somthing like that

var1 = 'avl-error';
var2 = 10610;

How can I get it in javascript or jQuery

Answer Source

Using regex in .match() you can find part of string you want.

var url = "";
var query = url.match(/ref=([^#]+)/)[1];
var hash = url.match(/#([^#]+)/)[1];
console.log(query, hash);

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download