admin管理员组

文章数量:1290976

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:

.html?referral=Google&visit=1

to:

.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!

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./directory/page.html?referral=Google&visit=1

to:

http://mywebsite./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!

Share Improve this question asked May 30, 2011 at 19:14 JohnJohn 731 silver badge3 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 10

Try this:

javascript: window.location = window.location.protocol + '//' + window.location.hostname + window.location.pathname + '?dog=Charlie&cat=Mittens';

本文标签: javascriptCreating Bookmarklet Append current URL with specific stringStack Overflow