简体   繁体   English

通过javascript修改网址的最佳方法是什么?

[英]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.

相关问题 通过 JavaScript 检查网站是否启动的最佳方法是什么 - What's the best way to check if a website is up or not via JavaScript 调试Javascript / AngularJS的最佳方法是什么? - What's the best way to debug Javascript/AngularJS? 为 OpenTest 学习 JavaScript 的最佳方法是什么 - What's the best way to learn JavaScript for OpenTest 将 JavaScript 注入 Puppeteer 的最佳方法是什么? - What's the best way to inject JavaScript into Puppeteer? 在JavaScript中计算关键字的最佳方法是什么? - What's the best way to count keywords in JavaScript? 用jQuery或Vanilla javascript在此URL字符串中获取数字的最佳方法是什么? - What's the best way to grab the number in this url string with jQuery or vanilla javascript? 通过Javascript检查加载控制状态的最佳方法是什么 - What is the best way to check control state on load via Javascript 通过javascript跟踪表单中的更改的最佳方法是什么? - What is the best way to track changes in a form via javascript? 在 javascript 中发送 object 作为浏览器 url 的查询参数的最佳方法是什么 - What is the best way to send an object as a query parameter of a browser url in javascript 在 JavaScript 中确定 URL 是否属于当前域的最佳方法是什么? - What is the best way to determine if a URL belongs to the current domain in JavaScript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM