Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating Bookmarklet: Append current URL with specific string

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!

like image 817
John Avatar asked May 30 '11 19:05

John


1 Answers

Try this:

javascript: window.location = window.location.protocol + '//' + window.location.hostname + window.location.pathname + '?dog=Charlie&cat=Mittens';
like image 71
Salman von Abbas Avatar answered Nov 02 '22 22:11

Salman von Abbas