Labels

ionic (40) Google Apps Script (28) Construct2 (6) Google API (5) Google Cloud (5) Java (5) presentation (5) jasper (4) plunker (4) Notepad++ (2) liferay (2) ms access (2) mysql (2) PHP (1) SQLite (1) android (1) blogspot (1) html5 (1) ionic-creator (1) javascript (1) mobile (1) plainjs (1) utilties (1)

Learn the powerful enterprise adaptable database:

Getting Started With ADABAS & Natural

Showing posts with label plainjs. Show all posts
Showing posts with label plainjs. Show all posts

Wednesday, February 1, 2017

JavaScript: Get Values From URL Parameters


.
JavaScript: Get Values From URL Parameters

1) Create demo script on GitHub


<!-- browse http://notarazi.github.io/demo/plainjs/geturlparameters.html?uid=a&age=20 -->
<html>
<head>
<script type="text/javascript">
       function getParam(name)
       {
           name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
           var regexS = "[\\?&]"+name+"=([^&#]*)";
           var regex = new RegExp( regexS );
           var results = regex.exec(window.location.href);
           if(results == null)
               return "";
           else  
               return results[1];
       }
      function getUrlData()
      {
           var uid = getParam("uid");
           var age = getParam("age");
           document.write("uid:"+uid+"<br/>age:"+age);
      }
</script>
</head>
<body onload="getUrlData()">
</body>
</html>

2) Test



3) GitHub

Run: http://notarazi.github.io/demo/plainjs/geturlparameters.html?uid=a&age=20
Source: https://github.com/notarazi/notarazi.github.io/blob/master/demo/plainjs/geturlparameters.html
.