Readdy Write  
0,00 €
Your View Money
Views: Count
Self 20% 0
Your Content 60% 0

Users by Links 0
u1*(Content+Views) 10% 0
Follow-Follower 0
s2*(Income) 5% 0

Count
Followers 0
Login Register as User

Javascript: mit Javascript den Query-Parameter abfragen

20.02.2023 (πŸ‘2220)

Javascript: mit Javascript den Query-Parameter abfragen

Wie kann man die Parameter in einer URL mittelns Javascript abfragen:

Einfach mit URL.searchparams.get(key)

var url=new URL(window.location.href);

..

var querypart=url.searchParams.get(key);  //query of that part

 

 

Code-Beispiel als function

get_query_parameters(parameters:string){ //parameters: 'k,f,s'

  //----< get_query_parameters >----

  //get url

  var url=new URL(window.location.href);

 

  //split the input parameters into an array [{k,f,s}]

  var arrParameters=parameters.split(",");

 

  //prepare output result

  var querystring:string='';

 

  //*loop: all parameters and get the url-query part

  arrParameters.forEach(key=>{

    var querypart=url.searchParams.get(key);  //query of that part

    if(querypart){ //if querypart exists

      //add the querypart to the output

      querystring='&' + key + "=" + querypart;

    }

  });

 

  //*output result

  return querystring;

  //----</ get_query_parameters >----

}

Aufruf

var filters=this.get_query_parameters("k,f,s");

 

 

Ein Bild, das Text enthΓ€lt.

Automatisch generierte Beschreibung