Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Create a Safari dictionary button Web Browsers

Apple's Sherlock buttons didn't offer the functionality I missed most, from MerriamWebster.com's old javascript dictionary button. Written for older versions of Netscape or MSIE, the freely available button doesn't work with Safari. The nice thing about the button was that you could either highlight a word in a page and punch the button for lookup OR just punch the button and enter a word into a dialog box.

Some slight tinkering with that javascript produced the following -- enter it as one long line with no added spaces (just remove the line breaks):

javascript:x=escape(getSelection());if(!x)%7Bvoid(x=prompt
('Word?',''))%7D;window.location='http://dictionary.reference.com/
search?q='+x

Of course, you can replace the URL with your preferred dictionary site--but you may have to change the syntax a bit.

    •    
  • Currently 2.80 / 5
  You rated: 4 / 5 (5 votes cast)
 
[20,604 views]  

Create a Safari dictionary button | 26 comments | Create New Account
Click here to return to the 'Create a Safari dictionary button' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Create a Safari dictionary button?
Authored by: Tice2 on Jul 22, '03 11:11:22AM

Umh ... could you please post the full code. Is this a button (<input type="button">) or a link, or a JavaScript for the head-section? How to use it?

---
Greetings Tice ; )



[ Reply to This | # ]
Create a Safari dictionary button?
Authored by: franny on Jul 22, '03 11:36:21AM

- Add a new bookmark in Safari. Doesn't matter what page you're on when you do it, because you're going to replace the URL with the javascript code.

- Give it a descriptive name like "dictionary." If you choose to keep it in the Bookmark Bar, it will show up as a one-word link that will act like a button.

- In your bookmarks, edit the link associated with your new bookmark; replace the "http://www...." with the javascript code posted above.

- try it!

Cool hint, thanks for posting.



[ Reply to This | # ]
Create a Safari dictionary button?
Authored by: Han Solo on Jul 22, '03 09:24:15PM
Even easier than the steps above is to highlight the text in Safari (make sure you have all of it!), then click and hold the highlighted text, then drag it to the bookmark bar. Safari will ask you what you want to name it; type in something pithy.

Note: If you copy something with linebreaks (like the code in the original hint), you will manually need to edit out each occurrence of the code '%0A', which represents the linebreaks, before it will work.

Note: These 'bookmarklets' do not have to live on your bookmark bar in Safari (or Mozilla, etc.): they will happily work in a folder, if you so choose.

[ Reply to This | # ]

The Easiest Way
Authored by: discordantus on Jul 23, '03 08:10:03PM
drag this link to your bookmark bar. it should create a nice little "bookmarklet", which will run the script when you click it.

[ Reply to This | # ]
Create a Safari dictionary button
Authored by: otsune on Jul 22, '03 11:42:41AM
Such examples also exist.
Google Cache
from Safari no dogubako(Safari bookmarklet) (in japanese)

[ Reply to This | # ]
Merriam-Webster button wannabe
Authored by: firthy374 on Jul 22, '03 11:48:01AM
This little mod to your javascript makes the button work with M-W: javascript:x=escape(getSelection());if(!x)%7Bvoid(x=prompt('Merriam-Webster%20Dictionary%20search:',''))%7D;window.location=window.location='http://www.m-w.com/cgi-bin/dictionary?book=dictionary&va='+x;

[ Reply to This | # ]
Create a Safari dictionary button
Authored by: Jay on Jul 22, '03 12:30:21PM

Works great, what a fantastic tip. You can change the "dictionary" part of the URL to "thesaurus" and it will give you a quick shortcut out of writer's block!



[ Reply to This | # ]
Sweet!
Authored by: porkchop_d_clown on Jul 22, '03 01:27:15PM

I had no idea you could embed javascript in a bookmark like that!

---
Everyone loves a clown, but no one will lend him money!



[ Reply to This | # ]
Create a Safari dictionary button
Authored by: brianw on Jul 22, '03 01:31:11PM
I posted a few other similar bookmarklets on my weblog a few months ago that some of you might be interested in. Go crazy, make more for your favorite sites. They're extremely handy in Safari when tossed in the toolbar so you can use them with Command-1, Command-2, etc.

[ Reply to This | # ]
Create Safari Googling buttons
Authored by: noel_gomez on Jul 22, '03 05:25:15PM

I modified this for google reference sites I use most. Here is my contribution.

Google Glossary

javascript:x=escape(getSelection());if(!x)%7Bvoid(x=prompt('Google Glossary%20Lookup%20search:',''))%7D;window.location=window.location='http://labs.google.com/glossary?q='+x+'&btnG=Google+Glossary+Search'

Google News

javascript:x=escape(getSelection());if(!x)%7Bvoid(x=prompt('Google News%20Lookup%20search:',''))%7D;window.location=window.location='http://news.google.com/news?hl=en&edition=usa&q='+x+'&btnG=Search+News'

Google Groups

javascript:x=escape(getSelection());if(!x)%7Bvoid(x=prompt('Google News%20Lookup%20search:',''))%7D;window.location=window.location='http://groups.google.com/groups?q='+x+'&ie=ISO-8859-1&hl=en&btnG=Google+Search'

Google Image

javascript:x=escape(getSelection());if(!x)%7Bvoid(x=prompt('Google News%20Lookup%20search:',''))%7D;window.location=window.location='http://images.google.com/images?q='+x+'&ie=ISO-8859-1&hl=en&btnG=Google+Search'



[ Reply to This | # ]
Create Safari Googling buttons
Authored by: mark hunte on Jul 22, '03 07:48:11PM

Thanks for the tips, just been playing and thought this one might be handy if it not done already. ( see below)
Yes it for MacOShints, I know this will come in handy for me at least.

Also if you want to create your own as I have just done, All I did was go to the search field on MacOShints enter my query (quicktime)
and hit search. once the search completed, I just copied the info from the address bar, shown here.
http://www.macosxhints.com/search.php?query=quicktime&type=stories&mode=search&keyType=all
I then pasted it into the javascript location , replacing the quicktime part with '+x+'
This is the finished script. to get it running just follow the tips posted before

javascript:x=escape(getSelection());window.location='http://www.macosxhints.com/search.php?query='+x+'&type=stories&mode=search&keyType=all';

---
mh

[ Reply to This | # ]

Create Safari Googling buttons
Authored by: mark hunte on Jul 22, '03 07:55:04PM

Sorry forgot to add you can use my tip to get the info you need for you own javascripts from different sites..

thanks

---
mh



[ Reply to This | # ]
sends 'null' on cancel
Authored by: rgray on Jul 22, '03 08:09:40PM

Love this tip, but..... ;-}

If I hit cancel instead of sending a word for look up in the Meriam-Webster version of this tip, the dialogue does not cancel! In fact it sends 'null'!.. and returns a definition of null.

How can I make 'cancel' cancel?



[ Reply to This | # ]
sends 'null' on cancel
Authored by: firthy374 on Jul 23, '03 02:42:58PM
This should work:

javascript:x=escape(getSelection());if(!x)%7Bvoid(x=prompt('Merriam-Webster%20Dictionary%20search:',''))%7D;
if(x!=null)%7Bwindow.location='http://www.m-w.com/cgi-bin/dictionary?book=dictionary&va='+x%7D


[ Reply to This | # ]
sends 'null' on cancel
Authored by: jpoage on Apr 27, '05 05:52:26PM

How would you get this to open in a new window, instead of the current window? Is that even possible? I tried using the "window.open" command, but I'm not smart ... :)



[ Reply to This | # ]
Create a Safari dictionary button
Authored by: bdm on Jul 22, '03 10:39:59PM

Great tip. Now, for the javascript-challenged amongst us, how can it be modified to open the dictionary in a new tab rather than on top of the current window?

bdm



[ Reply to This | # ]
Create a Safari dictionary button
Authored by: Anonymous on Jul 22, '03 11:19:41PM

I doubt that you can do that; HTML doesn't know about Safari tabs. You could, however, open in a new window:

javascript:q=escape(getSelection());if(!q)%7Bvoid(q=prompt('Search%20Everything%20for%20what?',''))%7D;
if(q)window.open('http://www.everything2.com/?node='+escape(q))

Basically, substitute window.open for location.href.



[ Reply to This | # ]
Key Difference Between Safari JavaScript Bookmarks and IE JavaScript Bookmarks
Authored by: Anonymous on Jul 22, '03 11:11:47PM

First off, thanks a ton for figuring this out and sharing it.

Secondly, for those following along at home, here's the key difference that makes this bookmark JavaScript work in Safari, where others did not: substitute every { character in your JavaScript with %7B, and every } character with %7D.

If you're importing bookmarks from NS or IE, make sure that you change this.

Now I can use my Everything lookup again!

javascript:q=escape(getSelection());if(!q)%7Bvoid(q=prompt('Search%20Everything%20for%20what?',''))%7D;
if(q)location.href='http://www.everything2.com/?node='+escape(q)



[ Reply to This | # ]
Create a Safari dictionary button
Authored by: ruebenschuss on Jul 23, '03 01:53:05AM

How cool is that ???
I did'n know either about java-script buttons. But it will be my favorite toy in the next couple of days...

I use it for the LEO German-English dictionary and amended the code. Try this:

javascript:x=escape(getSelection());if(!x)%7Bvoid(x=prompt('Word?',''))%7D;window.location='http://dict.leo.org/?search='+x+'&searchLoc=0&relink=on&spellToler=standard&sectHdr=on&tableBorder=1&cmpType=relaxed&lang=en'



[ Reply to This | # ]
Create a Safari dictionary button
Authored by: cyberbrent on Jul 23, '03 02:41:20AM

How about this one for FROOGLE GOOGLE. The Google site that looks up price comparisons on products. Its a great site and an awesome way to find a deal without all the ADS!

javascript:x=escape(getSelection());if(!x)%7Bvoid(x=prompt('FroogleGoogle%20Item%20Lookup%20search:',''))%7D;window.location=window.location='http://froogle.google.com/froogle?hl=en&edition=usa&q='+x+'&btnG=Google+Search'

Happy Shopping!

Regards

Brent

---
"You alone define your limitations"



[ Reply to This | # ]
Create a Safari dictionary button
Authored by: jjm on Jul 23, '03 01:11:41PM

I'm new at javascript.... and would like to create a "button" for the All Music Guide (allmusic.com). I've tried copying a few of the examples, but to no avail. Could anyone help ?



[ Reply to This | # ]
Frames don't pick up selected text?
Authored by: usermac on Jul 23, '03 11:31:35PM

This all works great but I found that when you select a word in a frame, it doesn't carry it instead it brings up the dialog box as if you never highlighted a word. Any ideas? See http://www.aolserver.com/docs to try this out.



[ Reply to This | # ]
Frames don't pick up selected text?
Authored by: unique_id on Sep 08, '03 07:31:22PM

Google's toolbar buttons can handle frames.

http://www.google.com/options/netscape6.html

Grab the "GoogleSearch" button, and modify the url in the javascript with whatever sites you like.



[ Reply to This | # ]
dict.org
Authored by: rgray on Nov 08, '03 01:36:29PM

Does anyone have one of these for dict.org? or know the necessary syntax? pls?



[ Reply to This | # ]
dict.org
Authored by: rgray on Jul 09, '04 04:16:23PM
Finally moved my own boney ass and did it... javascript:x=escape(getSelection());if(!x)%7Bvoid(x=prompt('DICT.org%20search:',''))%7D;if(x!=null)%7Bwindow.location='http://www.dict.org/bin/Dict?Form=Dict2&Database=*&Query='+x%7D

[ Reply to This | # ]
Create a Safari dictionary button
Authored by: DCJ001 on Nov 13, '10 07:56:53PM

Here we are, more than seven years after the original post,

The following Javascript bookmarklet will take you to Merriam-Webster's online for a highlighted word, or, if there is no highlighted word, a pop-up search window will appear so that you may enter the word that you would like to define. If you change your mind, after the pop-up search window appears, you can click on the "Cancel" button or the "Escape" key, without leaving the existing website.

I have this bookmarklet located in the first position off the edge of my bookmarks bar so that I can use it by pressing Command-1:

javascript:x=escape(getSelection());if(!x)%7Bvoid(x=prompt('Merriam-Webster%20Dictionary%20search:',''))%7D;if(x!=null)%7Bwindow.location='http://www.m-w.com/cgi-bin/dictionary?'+x%7D



[ Reply to This | # ]