简体   繁体   中英

How to change a URL query with Javascript

i am playing around a bit with html (just using twitter for a play, not using oauth etc because i am just wanting to change a url query).

This is the current "query"

https://twitter.com/search?q=%23html5

So as you can see the query is html5

I want to in html/javascript have it so it goes like this

https://twitter.com/search?q= 'user entered data from a textbox'

can someone give me a bit of help with this, i know how to typically do it on a visual basic program etc but javascript/html5 got me beat even though i know its probably going to be simple

So basically the user would click an on screen button after entering text and the q would change to that.

Cheers

See if this helps:

var search = encodeURIComponent(input.value);
url = url.replace(/?q=.*/, '?q='+ search); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM