Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var parts = document.location.href.split("/");
- var id = parts[parts.length-1];
- var url = document.URL.split('/');
- var id = url.pop();
- var id = url[url.lengh-1];
- function isNumeric(n) {
- return !isNaN(parseFloat(n)) && isFinite(n);
- }
- function GetIdIfExists() {
- var parts = document.location.href.split("/");
- var id = parts[parts.length - 1];
- if (isNumeric(id)) {
- return parseInt(id);
- } else {
- return null;
- }
- }
- //url = https://stackoverflow.com/questions/15761950/how-do-get-optional-parameter-value-using-javascript-in-mvc
- > GetIdIfExists()
- < null
- //url = https://stackoverflow.com/questions/15761950/how-do-get-optional-parameter-value-using-javascript-in-mvc/0
- > GetIdIfExists()
- < 0
Add Comment
Please, Sign In to add comment