How to get text from Address Bar in Firefox extension

自作多情 提交于 2019-12-04 02:42:34
Marcel Korpel

It doesn't seem to be possible in Google Chrome, as answers to this question say.

But with Firefox, you may have a look at several extensions mentioned here or at this one and try to figure out how they did what they did. I searched MDC a bit, but without luck.

I don't have any experience with Firefox extensions, so I hope this will be helpful to someone who can give a more precise explanation.

I think you would need to hijack the "ontextentered" event for the url bar. I'm assuming you'd want Firefox 4 which is around the corner, so look at:

http://mxr.mozilla.org/mozilla2.0/source/browser/base/content/browser.xul#656

You can add a keypress listener to "urlbar" to get text as it is entered as well.

e.g.:

document.getElementById("urlbar").setAttribute("ontextentered", "foobar(param);");

function foobar(param) {
       // do somethign w/ param
       // finally call original method if you aren't hijacking the text that was entered
       document.getElementById("urlbar").handleCommand(param);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!