搜尋 Mozilla 技術支援網站

防止技術支援詐騙。我們絕對不會要求您撥打電話或發送簡訊,或是提供個人資訊。請用「回報濫用」功能回報可疑的行為。

Learn More

Javascript bookmark dialogs stopped working

  • 2 回覆
  • 7 有這個問題
  • 3 次檢視
  • 最近回覆由 trocon

more options

I have some bookmarks on my Bookmarks Toolbar whose address is a Javascript snippet:

javascript:Qr=document.getSelection();if(!Qr){void(Qr=prompt('Enter subject to lookup in Wikipedia:',''))}if(Qr)location.href='http://en.wikipedia.org/wiki/Special:Search/'+escape(Qr)+'%20'

This will open a dialog box asking "Enter subject to lookup in Wikipedia", and takes that word or phrase and passes it on to Wikipedia's search page. With some editing, this code can also work for other sites, like dictionary.com.

So, when I upgraded to Firefox 8, these JS bookmarks turned into dotted squares for icons, and they no longer open a dialog box. Instead, only the site itself displays.

I've searched for a solution, but all I found were references to "keyword bookmarks". But AFAIK this is a different concept, because they're meant to be typed in the address bar, e.g. "w searchterm", and I don't know how it could be made into an item on the bookmark toolbar.

Any ideas for a workaround?

I have some bookmarks on my Bookmarks Toolbar whose address is a Javascript snippet:<br /> <br /> <pre><nowiki>javascript:Qr=document.getSelection();if(!Qr){void(Qr=prompt('Enter subject to lookup in Wikipedia:',''))}if(Qr)location.href='http://en.wikipedia.org/wiki/Special:Search/'+escape(Qr)+'%20'</nowiki></pre> This will open a dialog box asking "Enter subject to lookup in Wikipedia", and takes that word or phrase and passes it on to Wikipedia's search page. With some editing, this code can also work for other sites, like dictionary.com. So, when I upgraded to Firefox 8, these JS bookmarks turned into dotted squares for icons, and they no longer open a dialog box. Instead, only the site itself displays. I've searched for a solution, but all I found were references to "keyword bookmarks". But AFAIK this is a different concept, because they're meant to be typed in the address bar, e.g. "w searchterm", and I don't know how it could be made into an item on the bookmark toolbar. Any ideas for a workaround?

由 cor-el 於 修改

被選擇的解決方法

In Firefox 8 getSelection() returns an object and no longer a string.
So you need to force it to a string by either adding +"" or use the toString() method.

Qr=document.getSelection()+"";
Qr=document.getSelection().toString();

從原來的回覆中察看解決方案 👍 2

所有回覆 (2)

more options

選擇的解決方法

In Firefox 8 getSelection() returns an object and no longer a string.
So you need to force it to a string by either adding +"" or use the toString() method.

Qr=document.getSelection()+"";
Qr=document.getSelection().toString();

more options

Excellent, thanks for such a prompt and concise solution.

I could not get the second method (toString) to work, for some reason... it seems to pass the entire function on to the website. However, the first one works perfectly, so I just changed them all that way.