Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
programmieren:javascript:url_mit_paramatern_aendern_und_laden [2022/01/31 20:43] jgehrkeprogrammieren:javascript:url_mit_paramatern_aendern_und_laden [2022/12/17 12:28] (current) – external edit 127.0.0.1
Line 4: Line 4:
  
 <code javascript> <code javascript>
- const url_host          = window.location.origin;            // https://www.domain.com/ +const url_host          = window.location.origin;            // https://www.domain.com/ 
- const url_path          = window.location.pathname;          // folder/subpage.php/ +const url_path          = window.location.pathname;          // folder/subpage.php/ 
- const url_search_string = window.location.search;            // ?parameter=true&other_param=1024 +const url_search_string = window.location.search;            // ?parameter=true&other_param=1024 
- const url_params_object = new URLSearchParams( url_search ); // converts params to manipulatable object +      url_params_object = new URLSearchParams( url_search_string ); // converts params to manipulatable object 
-       url_params_object.set( 'other_param', 'new_value');    // change a parameter +      url_params_object.set( 'other_param', 'new_value');    // change a parameter 
- const url_params_string = url_params.toString();             // get paramaters as string +const url_params_string = url_params.toString();             // get paramaters as string 
- const new_url           = url_host + url_path + '?' + url_params_string;+const new_url           = url_host + url_path + '?' + url_params_string;
  
- window.location.replace( new_url );+window.location.replace( new_url );
 </code> </code>
  
 **Hinweis:** nicht IE11 kompatibel, wegen URLSearchParams() **Hinweis:** nicht IE11 kompatibel, wegen URLSearchParams()
 +
 +**MDN Doku:**
 +  * [[https://developer.mozilla.org/en-US/docs/Web/API/Window/location|window.location]]
 +  * [[https://developer.mozilla.org/de/docs/Web/API/URLSearchParams|new URLSearchParams( url_search )]]

Page Tools