搜索 | 用户支持

防范以用户支持为名的诈骗。我们绝对不会要求您拨打电话或发送短信,及提供任何个人信息。请使用“举报滥用”选项报告涉及违规的行为。

Learn More

Javascript bookmark dialogs stopped working

  • 2 个回答
  • 7 人有此问题
  • 1 次查看
  • 最后回复者为 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.