@@ -124,18 +124,13 @@ <h3>1. Change the Content of an Element</h3>
124124</ pre >
125125
126126<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
127- <!--~~~~~~~~~~~~~~~~~~~~~~~ 01. change content using innerHTML ~~~~~~~~~~~~~~~~-->
128- < p align ="center " >
129- < a href =""
130- target ="_blank " rel ="noopener noreferrer ">
131- < img class ="displayed "
127+ <!--~~~~~~~~~~~~~~~~~~~~~~~~ 01. example change content using innerHTML ~~~~~~~~~~~~~~~~~~~~~~~~-->
128+ < img class ="displayed "
132129 src ="./images/image001.gif?raw=true "
133130 loading ="lazy "
134- style ="width:40%; "
135- title =""
136- alt =". " />
137- </ a >
138- </ p >
131+ style ="width:531px; height:94px; "
132+ title ="Example changing content using innerHTML "
133+ alt ="Example changing content using innerHTML. " />
139134<!-- image001.gif -->
140135<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
141136< h4 > In this example</ h4 >
@@ -1763,20 +1758,21 @@ <h1 style="color: green">
17631758
17641759</ html >
17651760</ pre >
1766-
17671761<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
17681762< h4 > Output:</ h4 >
17691763<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
1770- <!--~~~~~~~~~~~~~~~~~~~~~~~ 39. ~~~~~~~~~~~~~~~~-->
1764+ <!--~~~~~~~~~~~~~~~~~~~~~~~~~~~ 39. g4g - listing url and hostname ~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~-->
17711765< p align ="center " >
17721766< a href =""
17731767 target ="_blank " rel ="noopener noreferrer ">
17741768 < img class ="displayed "
17751769 src ="./images/image039.png?raw=true "
17761770 loading ="lazy "
17771771 style ="width:40%; "
1778- title =""
1779- alt =". " />
1772+ title ="GeeksforGeeks URL is: https://ide.geeksforgeeks.org/tryit.php,
1773+ hostname is: ide.geeksforgeeks.org "
1774+ alt ="GeeksforGeeks URL is: https://ide.geeksforgeeks.org/tryit.php,
1775+ hostname is: ide.geeksforgeeks.org. " />
17801776</ a >
17811777</ p >
17821778<!-- image039.png -->
@@ -1794,24 +1790,22 @@ <h4>Syntax</h4>
17941790< h4 > Example: In this example, we will ask for the URL to the user and then will perform the
17951791extraction of the hostname on that URL.</ h4 >
17961792<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
1797-
17981793< pre >
1799- <!DOCTYPE html>
1800- < html >
1801-
1802- < head >
1803- < title > Extracting URL</ title >
1804- </ head >
1794+ <!DOCTYPE html>
1795+ <html>
1796+ <head>
1797+ <title>Extracting URL</ title >
1798+ </head>
18051799
1806- < body >
1807- < h1 style ="color: green; "> GeeksforGeeks< /h1 >
1808- < b > Extracting URL</ b >
1809- < br > < br >
1810- < form name ="f1 ">
1811- < input type ="text " name ="txt " placeholder ="Paste URL " />
1812- < input type ="button " value ="click " onclick ="url2() " />
1813- < /form >
1814- < script >
1800+ < body>
1801+ < h1 style="color: green;"> GeeksforGeeks< /h1>
1802+ <b> Extracting URL</b>
1803+ <br><br>
1804+ < form name="f1">
1805+ < input type="text" name="txt" placeholder="Paste URL" />
1806+ < input type="button" value="click" onclick="url2()" />
1807+ < /form>
1808+ < script>
18151809 function url2() {
18161810
18171811 let url3 = document.f1.txt.value;
@@ -1820,7 +1814,7 @@ <h1 style="color: green;">GeeksforGeeks</h1>
18201814
18211815 let host = "";
18221816
1823- for ( i = j + 3 ; i < url3 . length ; i ++ ) {
1817+ for (i = j + 3; i < url3.length; i++) {
18241818 if (url3.charAt(i) != '/') {
18251819 host = host + "" + url3.charAt(i);
18261820 } else {
@@ -1829,12 +1823,11 @@ <h1 style="color: green;">GeeksforGeeks</h1>
18291823 }
18301824 document.write(host);
18311825 }
1832- < /script >
1833- < /body >
1826+ < /script>
1827+ < /body>
18341828
1835- < /html >
1829+ < /html>
18361830</ pre >
1837-
18381831<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
18391832< h4 > Output:</ h4 >
18401833<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
@@ -1867,17 +1860,15 @@ <h4>Syntax</h4>
18671860<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
18681861< h4 > Return Value: It returns a string value that represents the full URL of the document.</ h4 >
18691862<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
1870-
18711863< pre >
1872- < script >
1864+ < script>
18731865// Get the current URL using document.URL
18741866let currentUrl = document.URL;
18751867
18761868// Log the URL to the console
18771869console.log(currentUrl);
1878- < /script >
1870+ < /script>
18791871</ pre >
1880-
18811872<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
18821873< h4 > Output</ h4 >
18831874<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
@@ -1894,13 +1885,13 @@ <h4>Syntax</h4>
18941885< pre > window.location.href</ pre >
18951886
18961887< pre >
1897- < script >
1888+ < script>
18981889// Get the current URL using document.URL
18991890let currentUrl = document.URL;
19001891
19011892// Log the URL to the console
19021893console.log(currentUrl);
1903- < /script >
1894+ < /script>
19041895</ pre >
19051896
19061897<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
@@ -1935,7 +1926,6 @@ <h3 id="D12-01">Method 1: Using the URLSearchParams Object</h3>
19351926<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
19361927< h4 > Syntax:</ h4 >
19371928<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
1938-
19391929< pre >
19401930let paramString = urlString.split('?')[1];
19411931let queryString = new URLSearchParams(paramString);
@@ -1944,38 +1934,36 @@ <h4>Syntax:</h4>
19441934 console.log("Value is: " + pair[1]);
19451935}
19461936</ pre >
1947-
19481937<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
19491938< h4 > Example: In this example we retrieves URL parameters using JavaScript. It splits the URL,
19501939extracts parameters with < b > < mark > URLSearchParams()</ mark > </ b > , and logs each
19511940< b > < mark > key-value</ mark > </ b > pair to the console when the button is clicked.</ h4 >
19521941<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
1953-
19541942< pre >
1955- < !DOCTYPE html>
1956- < html >
1957- < head >
1958- < title >
1943+ < !DOCTYPE html>
1944+ < html>
1945+ < head>
1946+ < title>
19591947 How To Get URL Parameters using JavaScript?
1960- < /title >
1961- < /head >
1962- < body >
1963- < h1 style ="color:green; ">
1948+ < /title>
1949+ < /head>
1950+ < body>
1951+ < h1 style="color:green;">
19641952 GeeksforGeeks
1965- < /h1 >
1966- < b >
1953+ < /h1>
1954+ <b>
19671955 How To Get URL Parameters
19681956 With JavaScript?
1969- </ b >
1970- < p > The url used is:
1957+ </b>
1958+ <p> The url used is:
19711959 https://www.example.com/login.php?a=GeeksforGeeks&b=500&c=Hello Geeks
1972- </ p >
1973- < p >
1960+ </p>
1961+ <p>
19741962 Click on the button to get the url
19751963 parameters in the console.
1976- </ p >
1977- < button onclick ="getParameters() "> Get URL parameters < /button >
1978- < script >
1964+ </p>
1965+ < button onclick="getParameters()"> Get URL parameters < /button>
1966+ < script>
19791967 function getParameters() {
19801968 let urlString =
19811969 "https://www.example.com/login.php?a=GeeksforGeeks&b=500&c=Hello Geeks";
@@ -1986,11 +1974,10 @@ <h1 style="color:green;">
19861974 console.log("Value is:" + pair[1]);
19871975 }
19881976 }
1989- </ script >
1990- </ body >
1991- </ html >
1992- </ pre >
1993-
1977+ </script>
1978+ </body>
1979+ </html>
1980+ </ pre >
19941981<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
19951982< h4 > Output:</ h4 >
19961983<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
@@ -2633,12 +2620,3 @@ <h4>Output:</h4>
26332620 <!- script was here -->
26342621 </ body >
26352622</ html >
2636-
2637-
2638-
2639-
2640-
2641-
2642-
2643-
2644-
0 commit comments