7

I am attempting to create a bookmarklet that will change the URL of the page I am currently on, and load a new page with the URL string changed. I have reviewed a number of other threads on bookmarklets, but I haven't found a solution that works for me.

I would like to be able to change a URL that looks like this:

http://mywebsite.com/directory/page.html?referral=Google&visit=1

to:

http://mywebsite.com/directory/page.html?dog=Fido&cat=Mittens

The three goals:

1) Delete anything in the existing URL after the ? mark.

2) Append "dog=Charlie&cat=Mittens" after the question mark.

3) Immediately load this new page, with the new URL

It seems simple enough, but I have not been able to figure out how to do this. Any help would be greatly appreciated!

John
  • 73
  • 1
  • 3

1 Answers1

10

Try this:

javascript: window.location = window.location.protocol + '//' + window.location.hostname + window.location.pathname + '?dog=Charlie&cat=Mittens';
Samuel Katz
  • 24,066
  • 8
  • 71
  • 57
  • Thanks for the suggestion @SalmanPK. Alas, I tried that as `javascript:window.location = window.location.hostname + window.location.pathname . '?dog=Charlie&cat=Mittens';` and nothing happens to the page or URL when I click the bookmarklet. – John May 30 '11 at 21:37