var str = URL.search
Valor de retorno: esta propiedad
Ejemplo 1:
HTML
<!DOCTYPE html> <html> <body> <h1>GeeksforGeeks</h1> <button onclick="get()" x='15' y='30'> Click on Me! </button> <script type="text/javascript"> function get() { var url = new URL( 'https://www.geeksforgeeks.org/GeeksforGeeks/search?gfg'); console.log( "search string of current URL is :", url.search); } </script> </body> </html>
Producción:
Ejemplo 2:
HTML
<!DOCTYPE html> <html> <body> <h1>GeeksforGeeks</h1> <div id="abc"></div> <br><br> <button onclick="get()" x='15' y='30'> Click on Me! </button> <script type="text/javascript"> function get() { var url = new URL( 'https://www.geeksforgeeks.org/GeeksforGeeks/search?gfg'); a = document.getElementById("abc"); a.innerHTML = "search string of current URL is : " + url.search; } </script> </body> </html>
Producción:
Navegadores compatibles:
- Safari
- Ópera
- Cromo
- Borde
- Firefox