2016-04-11 13 views
1

URLから値を取得javascript - カスタムURLパターン

;私が欲しいもの

それはJavaScriptを使用して可能です..私はこのURL別にapp_id & dash_idをしたい

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

のですか?

答えて

2

この

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);

+1

大感謝をしてみてください!できます ...! –

1

を試してみてくださいあなたは正規表現を使用する必要がありますが、念のためにあなたがあなたのためにそれを行うためのツールが欲しい、http://txt2re.com/