Related Articles

Related Articles

JavaScript | Know the value of GET parameters from URL
  • Last Updated : 16 Apr, 2019

In order to know the parameters, those are passed by the “GET” method, like sometimes we pass the Email-id, Password, and other details. For that purpose, We are using the following snippet of code.

Example-1: This example get the value of “a” parameter from the URL.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>
        JavaScript |
      Know the value from GET parameters
    </title>
</head>
  
<body style="text-align:center;">
  
    <h1 style="color:green;">  
            GeeksForGeeks  
        </h1>
  
    <button onclick="myGeeks()">
        Click here
    </button>
  
    <p id="GFG_down"
       style="color:green;">
    </p>
  
    <script>
        function myGeeks() {
            var GFG_url_string = 
              
            var GFG_url = new URL(GFG_url_string);
            var c = GFG_url.searchParams.get("a");
            var p_down = document.getElementById("GFG_down");
            p_down.innerHTML = c;
        }
    </script>
</body>
  
</html>

chevron_right


Output:

  • Before clicking on the button:
  • After clicking on the button:

Example:This example get the value of all the parameters from the URL.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>
        JavaScript 
      | Know the value from GET parameters
    </title>
</head>
  
<body style="text-align:center;">
  
    <h1 style="color:green;">  
            GeeksForGeeks  
        </h1>
  
    <button onclick="myGeeks()">
        Click here
    </button>
  
    <p id="GFG_down"
       style="color:green;">
    </p>
  
    <script>
        function myGeeks() {
            var GFG_url_string = 
            var GFG_url = new URL(GFG_url_string);
            var a = GFG_url.searchParams.get("a");
            var b = GFG_url.searchParams.get("b");
            var c = GFG_url.searchParams.get("c");
            var p_down = document.getElementById("GFG_down");
            p_down.innerHTML = a + "<br>" + b + "<br>" + c;
        }
    </script>
</body>
  
</html>

chevron_right


Output:

  • Before clicking on the button:
  • After clicking on the button:

full-stack-img




My Personal Notes arrow_drop_up
Recommended Articles
Page :