How to append to an anchor's href attribute with JavaScript but not affect query string? -


i have links (they in array, not a elements)...

  • http://example.com
  • http://example.com?bob=true
  • http://example.com?sandy=true&bob=false

i want append after .com before start of query string.

example

  • http://example.com/search/results
  • http://example.com/search/results?bob=true
  • http://example.com/search/results?sandy=true&bob=false

what best way?

update

i answered own question, if solution can improved (or can see problem it) please post own answer.

i came this...

var append = '/search/results';  anchor.href = anchor.href.replace(/(\?|$)/, append + '$1');  

i thought omit parenthesis , reference $0, didn't work me :(


Comments

Popular posts from this blog

400 Bad Request on Apache/PHP AddHandler wrapper -

Add email recipient to all new Trac tickets -

php - Change action and image src url's with jQuery -