Bookmarklets

Prepopulate module was created for bookmarklets.

What's a bookmarklet?

Bookmarklets are links in your browser which "add one-click functionality to a browser or web page" says Wikipedia. For example, you could have a bookmarklet which makes it easier to post content to your website.

With the Prepopulate module, you can make bookmarklets that will fill out specific fields in your custom content types made through CCK.

How to edit a bookmarklet

Normal bookmarks on your browser's toolbar would have a title and a URL, which is just a plain web address starting with http://. A bookmarklet has a little script in the URL instead, starting with javascript:

Add a bookmark in your browser's favorites or bookmarks, or edit an existing one. In the case of Internet Explorer, you right click on the bookmark to access the properties, and then add in the javascript code (below) where it asks for the URL. It's the same for Firefox. In Safari you 'edit address'. Each browser is different.

Example bookmarklet code

Here is an example bookmarklet to post web links to a site

javascript:u=document.location.href;t=document.title;s=window.getSelection();
void(window.open(%22http://example.com/node/add/content-web-link?edit[title]=%22+escape(t)+
'&edit[body_filter][body]='+escape(s)+'&edit[field_url][0][value]='+escape(u),'_blank',
'width=1024,height=500,status=yes,resizable=yes,scrollbars=yes'));

This turns into a URL like this:

http://example.com/node/add/content-web-link
?edit[title]=drupal.org%20%7C%20Community%20plumbing&edit[body_filter][body]
=&edit[field_url][0][value]=http%3A//drupal.org/

The 's' variable puts in the selection, in the body of your node form; 'u' pulls in the current URL you are on; and 't' fills in the title. You can figure out the names of your fields by viewing the source, and modifying your field names accordingly.

Here's another example with different field names, and a link field with a title as well.

javascript:u=document.location.href;t=document.title;s=window.getSelection();void(window.open(%22http://example.com/node/add/blog?edit[title]=%22+escape(t)+'&edit[body_field][body]='+escape(s)+'&edit[field_link][0][url]='+escape(u)+'&edit[field_link][0][title]='+escape(t),'_blank','width=1024,height=500,status=yes,resizable=yes,scrollbars=yes'));

Feel free to add additional bookmarklet examples as child pages here.

AttachmentSize
bookmarklet.png8.49 KB
edit-bookmarklet-firefox.png46.52 KB
edit-bookmarkletsafari.png30.89 KB
edit-bookmarklet-url.png27.66 KB

Drupal 6 example

Brigadier - January 6, 2009 - 03:11

I'm using Drupal 6.8 with CCK 6.x-2.1 and Prepopulate 6.x-1.1.

This bookmarklet is almost the same as the one described above.

javascript:u=document.location.href;t=document.title;s=window.getSelection();void(window.open(%22http://example.com/node/add/customenode?edit[title]=%22+escape(t)+'&edit[body_field][body]='+escape(s)+'&edit[field_external_link][0][url]='+escape(u),'_blank','width=1024,height=500,status=yes,resizable=yes,scrollbars=yes'));

It fills in a textarea named "body" with the selected text. It fills in a CCK url called "field_external_link" with the URL. Notice one subtle difference: I had to use edit[body_field][body] - not edit[body_filter][body]. Not sure why but this one works for me.

Change "customenode" to your node type. Change "example.com" to your domain & base path.

Not working for me

Donovan - March 1, 2009 - 22:58

I tried this bookmarklet on Drupal 6.9 and Prepopulate 6.x-1.1, with only changes to the "customnode", link field name, and domain & base path; but it does not completely work -- i.e.:

1. the form is not opening in a new window
2. the form fields are being populated with the javascript code instead of the results of executing the code

Here's my edited bookmarklet:

<a href="javascript:u=document.location.href;t=document.title;s=window.getSelection();void(window.open(%22http://example.com/node/add/customnode?edit[title]=%22+escape(t)+'&edit[body_field][body]='+escape(s)+'&edit[field_link][0][url]='+escape(u),'_blank','width=1024,height=500,status=yes,resizable=yes,scrollbars=yes'));">Test</a>

Here are the results:

Title: *
" escape(t) '

Body: *
' escape(s) '

Link: *
' escape(u),'_blank','width=1024,height=500,status=yes,resizable=yes,scrollbars=yes'));

I know it's something simple, but can't figure it out. Any pointers are appreciated.

I can't figure out how to

aurelien-bordeaux - June 3, 2009 - 12:45

I can't figure out how to make it work ... but I would say that yourse doesn't because of the "href" at the beginning..

Its a bookmarklet, not a link..

viksit - July 22, 2009 - 17:11

Add a new bookmark to your browser, where the location is javascript: ....

Its not an html link.

--
Viksit Gaur
www.viksit.com

 
 

Drupal is a registered trademark of Dries Buytaert.