I want to create a bookmarklet that will allow users to submit URLS from sites on the fly as they browse.
I’m looking for three possible implementations of this bookmarklet.
-
Simply click the bookmarklet and be taken to the page with my form field and have the URL they just came from entered into the field.
-
Simply click the bookmarklet and be taken to the page with my form field and the link they had highlighted from the previous page is entered into the field.
-
The preferred option – Click the bookmarklet, a popup (similar to Twitter’s tweet box in size and function) opens with my form field pre-populated with the URL of the page they clicked the bookmarklet on. Like Twitter’s tweet box and facebook’s share box.
I typically don’t just give away code, but this is so simple I figure it’s worth sharing and explaining.
Compressed:
Expanded
The way this works is it just calls an anonymous closure to pass variables to the
window.openfunction. It passes the current page’s location as theurivalue in the query string.On the page containing your form, you’ll need to populate the correct field with the value from the query string.
Although this could be written without using a closure, you need to make sure that there isn’t a return value from whatever’s being called, as
javascript:<string value>will re-write the DOM with whatever text was in<string value>.