Firefox addon to do something everytime a user hits Enter in the address bar

萝らか妹 提交于 2019-12-24 01:36:04

问题


I'm trying to write an extension that monitors every time someone types hits enter when using the address bar. The steps would be something along the lines of

  1. User types in a bunch of text in the address bar and hits Enter
  2. My addon springs to life and receives what the user typed in
  3. My addon then decides what to do with the string the user typed in.

I get the url in step 2 by using var url = window.location.href. I also have most of step 3 written out already. The only probably I can't seem to figure out is how to monitor every tab to watch for when the user hits return.

I'm really new to Javascript, but regardless of that, any information would be appreciated.

This is what my myaddon.xul file looks like:

<overlay id="sample" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/x-javascript" src="chrome://myaddon/content/myaddon.js" />
<textarea id="urlbar" ontextentered="return myaddon_URLBar(param);" />
</overlay>

回答1:


I think the following link would help. You need to implement Progress Listeners, they allow extensions to be notified whenever some events happen associated with the document. You can also extend this to multiple tabs. Please try the link

https://developer.mozilla.org/en/Code_snippets/Progress_Listeners#Example.3a_Notification_when_the_value_in_Address_Bar_changes

Hope it helps :)



来源:https://stackoverflow.com/questions/3704364/firefox-addon-to-do-something-everytime-a-user-hits-enter-in-the-address-bar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!