0

Url is generated like this

/Home/LoadData?page=2&activeTab=House

How can I grab activeTab value?

user1765862
  • 13,635
  • 28
  • 115
  • 220

5 Answers5

3
function getURLParameter(name) {
    return decodeURI(
        (RegExp(name+ '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]
    );
}

and call it as getURLParameter('activeTab');

From Here

Community
  • 1
  • 1
Dipesh Parmar
  • 27,090
  • 8
  • 61
  • 90
2

please add this function in your javascript

and you can pass param name and you can get value

function getParameterByName(name)
{
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(window.location.search);
    if(results == null)
        return "";
    else
        return decodeURIComponent(results[1].replace(/\+/g, " "));
}

hope it's help for you .

Ravi Kavaiya
  • 829
  • 6
  • 16
1

You can use split

Live Demo

url.split('activeTab=')[1]
Adil
  • 146,340
  • 25
  • 209
  • 204
1

You can use javascript's substr() and .lastIndexOf():

var url = '/Home/LoadData?page=2&activeTab=House'; // window.location.href;

var activeTab = url.substr(url.lastIndexOf('=')+1); // outputs House

Find in FIDDLE

Jai
  • 74,255
  • 12
  • 74
  • 103
1

try something like this

 $(document).ready(function(){
    var url = 'http://stackoverflow.com/Home/LoadData?page=2&activeTab=House';
    alert(decodeURI(
            (RegExp('activeTab=' + '(.+?)(&|$)').exec(url)||[,null])[1]
        ));
});
rajesh kakawat
  • 10,826
  • 1
  • 21
  • 40