Get URL GET values using javascript

I had a situation of getting URL GET values to my web page without using server side scripting language like PHP, JSP or ASP.

So this is a simple way to get URL GET value to your web page using javaScript. When you don’t have any facilities to code server side scripts, you can use this technique to make your website more dynamic.

Simple example :

     <script>// Import GET Vars
           document.$_GET = [];
           var getVarsString = String(document.location).split('?');
              var getVars = getVarsString[1].split('&');
              for(var i=0; i<=(getVars.length); i++){
                    var getVarPair = getVars[i].split('=');
                    document.$_GET[getVarPair[0]] = getVarPair[1];
         function updateView(){
      <input id="txt" type="button" value="click" onclick="updateView();" />
      <div id="view"></div>
%d bloggers like this: