根据URL中的参数更改URL

时间:2014-02-01 23:19:46

标签: php jquery pagination

我有以下jQuery代码:

window.location.href = window.location.href.replace( /[\?#].*|$/, "?start_price=" + start_price + "&end_price=" + end_price + "&order_by=" + order_by);

这适用于取参数“?”后面的所有内容并更改它并将用户返回到原始URL,并在“?”后面进行自定义

Ex:http://example.com/80?start_price=80&end_price=120&order_by=price

网址可以采用以下格式:

1. http://example.com?start_price=80&end_price=120&order_by=price
2. http://example.com/80?start_price=80&end_price=120&order_by=price
3. http://example.com/120?start_price=80&end_price=120&order_by=price

现在我想将用户(独立于以后的参数是什么)发送到URL样式1,而不包含80或120.

我使用此代码显示产品。这些数字是分页数。所以基本上我希望用户在用户更改start_price,end_price或order_by的任何参数时进入第一页。

我不擅长这个可以在这里暗示的人吗?

1 个答案:

答案 0 :(得分:0)

这样的事情?

var parts = window.location.pathname.split('/'); //pathname to array
parts.splice(parts.length-1,1); // kill the last key
var newpathname = parts.join('/'); // reassemble

self.location.href = window.location.protocol+'://'+window.location.host+'/'+newpathname+'?'+window.location.search;

(未经测试,但应该有效)

相关问题