Guest User

Untitled

a guest
Nov 15th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. var parts = document.location.href.split("/");
  2. var id = parts[parts.length-1];
  3.  
  4. var url = document.URL.split('/');
  5.  
  6. var id = url.pop();
  7.  
  8. var id = url[url.lengh-1];
  9.  
  10. function isNumeric(n) {
  11. return !isNaN(parseFloat(n)) && isFinite(n);
  12. }
  13.  
  14. function GetIdIfExists() {
  15. var parts = document.location.href.split("/");
  16. var id = parts[parts.length - 1];
  17.  
  18. if (isNumeric(id)) {
  19. return parseInt(id);
  20. } else {
  21. return null;
  22. }
  23. }
  24.  
  25. //url = https://stackoverflow.com/questions/15761950/how-do-get-optional-parameter-value-using-javascript-in-mvc
  26. > GetIdIfExists()
  27. < null
  28.  
  29. //url = https://stackoverflow.com/questions/15761950/how-do-get-optional-parameter-value-using-javascript-in-mvc/0
  30. > GetIdIfExists()
  31. < 0
Add Comment
Please, Sign In to add comment