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.
html
< h1 style = "color:green;" > neveropen </ h1 > < button onclick = "myGeeks()" > Click here </ button > < p id = "GFG_down" style = "color:green;" > </ p > < script > function myGeeks() { var GFG_url_string = "https://ide.geeksforgeeks.org/login.php?a=GeeksForGeeks&b=100&c=Computer Science portal for Geeks"; 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 > |
Output:
Example 2:This example get the value of all the parameters from the URL.
html
< h1 style = "color:green;" > neveropen </ h1 > < button onclick = "myGeeks()" > Click here </ button > < p id = "GFG_down" style = "color:green;" > </ p > < script > function myGeeks() { var GFG_url_string = "https://ide.geeksforgeeks.org/login.php?a=GeeksForGeeks&b=100&c=Computer Science portal for Geeks"; 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 > |
Output: