[英]What's the best way to amend a url via javascript?
My wordpress site has a search form that is crap. 我的wordpress网站的搜索表单很垃圾。
It produces this search string: www.mysite.com/properties/?wpp_search[sort_order]=DESC&wpp_search[sort_by]=price&wpp_search[pagination]=on&wpp_search[per_page]=10&wpp_search[strict_search]=false&wpp_search[property_type]=residential_sales%2Cresidential_lettings%2Ccommercial%2Cfine_living&wpp_search[area]=&wpp_search[price][min]=&wpp_search[price][max]=&wpp_search[branch]=-1&wpp_search[bedrooms]=-1&wpp_search[department]=-1#propertycontent
它将产生以下搜索字符串:
www.mysite.com/properties/?wpp_search[sort_order]=DESC&wpp_search[sort_by]=price&wpp_search[pagination]=on&wpp_search[per_page]=10&wpp_search[strict_search]=false&wpp_search[property_type]=residential_sales%2Cresidential_lettings%2Ccommercial%2Cfine_living&wpp_search[area]=&wpp_search[price][min]=&wpp_search[price][max]=&wpp_search[branch]=-1&wpp_search[bedrooms]=-1&wpp_search[department]=-1#propertycontent
What's the best way to grab this string, and change certain aspects eg: [sort_order]=ASC
[sort_by]=price
捕获此字符串并更改某些方面的最佳方法是什么,例如:
[sort_order]=ASC
[sort_by]=price
Then reload the page displaying the new string and thus changing the form output? 然后重新加载显示新字符串的页面,从而更改表单输出?
尝试这个。
url.replace('[sort_order]=DESC','[sort_order]=ASC').replace('[sort_by]=price','[sort_by]=newPrice');
You can get the url's query portion using location.search
. 您可以使用
location.search
获取url的查询部分。 Look for the parameter, modify, reconstruct your url and assign that value to location
to load the page with that url. 查找参数,修改,重建您的url并将该值分配给
location
以使用该url加载页面。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.