Search code examples
javascripturl-pattern

javascript - Custom URL Pattern


Get Values from URL

var acutal_url = HTTP://my_host.com/account/apps/6/dashboard/6;

what i want is

var pattern_url = HTTP://my_host.com/account/apps/<int:app_id>/dashboard/<int:dash_id> ;

I want app_id & dash_id separately from this URL ..

Is it possible using JavaScript?


Solution

  • Try this

    var acutal_url = "HTTP://my_host.com/account/apps/6/dashboard/6"
    var app_id = acutal_url.substring( acutal_url.indexOf("/apps/") + 6, acutal_url.indexOf("/dashboard/") ); 
    
    var dash_id = acutal_url.substring( acutal_url.indexOf("/dashboard/") + 11 );  
    alert(app_id);
    alert(dash_id);