1

I have this URL and wanting to know how can I remove this section from it via a jQuery event.

Need to remove:

&activities_id=13&session_id=14&back=1

Original URL:

http://somedomain.com/ijob-css/index.php/search/default/index/area/act?query=&activities_id=13&session_id=14&back=1

EDIT

Sorry i think i havent included the most important section. I should change the Address BAR url not a normal string.

for example, if i have this url in the address bar - http://somedomain.com/ijob-css/index.php/ after change, address bar should contain http://somedomain.com/xxx=111, without page refreshing.

4

6 回答 6

2

你的意思是你想要没有查询参数部分的 URL 吗?如果然后看看这是否有帮助。

var test = 'http://somedomain.com/ijob-css/index.php/search/default/index/area/act?query=&activities_id=13&session_id=14&back=1';

alert(test.substring(0, test.indexOf('?')));

如果您想要直到第一个查询参数名称,那么只需寻找直到索引 &

更新 :

如果您使用的是 HTML5,那么您的要求是可能的。检查浏览器历史操作。您可以在此处找到有关此内容的详细信息。

我相信 replaceState() 是您问题的答案。但是,并非所有浏览器/版本都支持它。History.js 包装了 HTML5 状态特性,并为 HTML4 浏览器提供了额外的支持。

于 2013-09-17T04:57:36.243 回答
1
var index = original_url.indexOf("=");
var new_url = original_url.substring(0,index+1);
于 2013-09-17T04:58:42.430 回答
1

见下文。

var positionToSubstring = this.location.href.indexOf('&');
var newURI = this.location.href.substring(0, positionToSubstring);
于 2013-09-17T04:58:46.060 回答
1

用这个

var test='http://somedomain.com/ijob-css/index.php/search/default/index/area/act?query=&activities_id=13&session_id=14&back=1';
test=test.split('&')[0];

console.log(test);

输出

http://somedomain.com/ijob-css/index.php/search/default/index/area/act?query=

于 2013-09-17T04:59:51.253 回答
1
var lastPart = 'query=';
var url = 'http://somedomain.com/ijob-css/index.php/search/default/index/area/act?query=&activities_id=13&session_id=14&back=1'.split(lastPart)[0] + lastPart;
于 2013-09-17T04:57:46.497 回答
1

试试这个

var new_url = old_url.substring(0, old_url.indexOf('&'));

示例:http: //jsfiddle.net/SjrqF/

var url = 'youtube.com/watch?v=3sZOD3xKL0Y&feature=youtube_gdata';

url = url.slice( 0, url.indexOf('&') );

或者:

示例:http: //jsfiddle.net/SjrqF/1/

var url = 'youtube.com/watch?v=3sZOD3xKL0Y&feature=youtube_gdata';

url = url.split( '&' )[0];
于 2013-09-17T04:57:15.533 回答