Firefox 8.0: How do I allow JavaScript prompts in the navigation toolbar?
Literally since before the days of Firefox 1.x, I have had a few navigation bar links to simple JavaScripts that let me do some quick searching. They are all more or less the same code. One searches M-W.com and goes like this:
javascript:Qr=document.getSelection();if(!Qr){void(Qr=prompt('Enter%20word%20to%20find%20in%20Merriam-Webster%20Dictionary:',))}if(Qr)location.href='http://www.m-w.com/cgi-bin/dictionary?'+escape(Qr)+'%20'
Traditionally, when I wanted to search something, I could do one of two things. First, I could hit the button and I would get a prompt to type in what I was searching for. Second, I could highlight a word on a web page, hit the button, and it would look up the highlighted word.
When I upgraded to Firefox 8.0, these stopped working properly. Now I can still highlight and hit the botton, but the prompt no longer exists. It just forwards me the search URL without giving me a chance to type input. Is there anything I can do?
All Replies (2)
The getSelection() method now return an object, so you need to adjust that part of the code to make it work.
javascript:Qr=document.getSelection()+'';if(!Qr){void(Qr=prompt('Enter word to find in Merriam-Webster Dictionary:',))}if(Qr)location.href='http://www.m-w.com/cgi-bin/dictionary?'+escape(Qr)+' ';
Diubah
Here is one for Google: (which you can easily modify)
javascript:q%20=%20%20+%20(window.getSelection%20?%20window.getSelection()%20:%20document.getSelection%20?%20document.getSelection()%20:%20document.selection.createRange().text);%20if%20(!q)%20q%20=%20prompt('Enter%20your%20search%20here',%20);%20if%20(q!=null)%20location='http://google.com/search?query='%20+%20escape(q).replace(/%20/g,%20'+')+'&num=100';%20void%200
Search Google from a selection
-- http://www.ampercent.com/useful-search-bookmarklets/5269/
-- Firefox has a built-in context menu to do same.*
- *that is to do a search from a selected word with the default search engine (the one at the top)