I have a url http://local.evibe-dash.in/tickets/123?ref=avl-error#10610
I want to get ref=avl-error
and 10610
in two variable
for Example somthing like that
var1 = 'avl-error';
var2 = 10610;
How can I get it in javascript or jQuery
I have a url http://local.evibe-dash.in/tickets/123?ref=avl-error#10610
I want to get ref=avl-error
and 10610
in two variable
for Example somthing like that
var1 = 'avl-error';
var2 = 10610;
How can I get it in javascript or jQuery
Using regex in .match()
you can find part of string you want.
var url = "http://local.evibe-dash.in/tickets/123?ref=avl-error#10610";
var query = url.match(/ref=([^#]+)/)[1];
var hash = url.match(/#([^#]+)/)[1];
console.log(query, hash);
This was asked and answered multiple times on Stack.
Look at this posts:
How can I get query string values in JavaScript?
Parse query string in JavaScript
Basicly you have to:
Please use stack before asking. And give some reputation to people on the links above.
Try this function you get an array with query string key, it's value and the string after hash
var getUrlParameter = function getUrlParameter(sParam) {
var sPageURL = decodeURIComponent(window.location.search.substring(1)),
sURLVariables = sPageURL.split('&'),
sParameterName,
i;
for (i = 0; i < sURLVariables.length; i++) {
sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] === sParam) {
sParameterName[1] === undefined ? true : sParameterName[1];
}
if(window.location.href.indexOf("#") > -1) {
var url = window.location.href;
sParameterName[2] = url.match(/#([^#]+)/)[1];
}
}
return sParameterName;
};
var a = getUrlParameter('your-query-string-key');
console.log(a);