/    Sign up×
Community /Pin to ProfileBookmark

add string to the url using javascript

long story short

I have a site with a search engine which looks like the following after the user searched something:

mysite.com?search=text&position=1 for example

I need an anchor which would take the user to the same page but add another parameter..so I would have anchors which when pressed would go to

mysite.com?search=text&position=1&page=2

the way I tried was
<a href=”#” onclick=”javascript:document.location.href=concat(document.location.href,’&page=2′) but doesn;t seem to work. anyone has an ideea how I can do it?
10x in advance

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@gil_davisJun 26.2007 — &lt;script type="text/javascript"&gt;
function extendSearch(addon) {
window.location.search += addon;
}
&lt;/script&gt;
...
&lt;a href="#" onclick="extendSearch('&amp;page=2');return false"&gt;
Copy linkTweet thisAlerts:
@rshieldsNov 13.2008 — How can we modify extendSearch.js to open the link in a new window?
Copy linkTweet thisAlerts:
@biggie_macauthorNov 13.2008 — instead of

window.location.search += addon;

you write

window.open(window.location.href+=addon);
Copy linkTweet thisAlerts:
@rshieldsNov 13.2008 — Thanks for your help. When I tried the suggestion, both the parent window and the new window opened to the following address:

http://www.domain.com/&print=true

How can I get the new window to open to

http://www.domain.com/?&print=true

while leaving the parent window unchanged?
Copy linkTweet thisAlerts:
@biggie_macauthorNov 14.2008 — My bad, sorry, take out the "=" sign, leaving only

window.open(window.location.href+addon);
×

Success!

Help @biggie_mac spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...