简体   繁体   中英

JavaScript edit links

My internal search engine returns search results which look like this:

http://test.mobilkul.se/search/search.html

Right now this JavaScript adds for example "target=blank" and #search="query_String" to each link at the search results.

I am trying to edit the JavaScript so that every link will be changed from

"http://test.mobilkul.se/search/click?query..."

to

"http://test.mobilkul.se/search/fetch?query..."

I have tried to add:

.replace('search/click?query=','search/fetch?query=');

to different places in the JavaScript, but nothing happens..

Can anyone please help?

EDIT:

I have put up a JSfiddle here: http://jsfiddle.net/shibaja/kK2PZ/

The JavaScript is at the bottom of the html code.

I want to execute these commands on each link:

.replace('&url=%2Fsearch','&urlx=%2Fsearch')

.replace('search/click?query=','search/fetch?query=')

.replace('&title=file','&url=file')

.replace('&spaceId=','&space=')

But I dont know where to put them in the javascript.. Please save my day :)

Something like:

$('a[href*=query]').each(function(){
  $(this).attr('href', $(this).attr('href').replace('query', 'fetch'));
});

You can tweak to replace the more specific string ( search/click?query ).

Also, remember that replace will not affect the original string, but will return you a new one in the way you want.

Hope it helps.


Here is the JSFiddle: http://jsfiddle.net/V8B8N/

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