响应Firefox插件中的地址栏键事件 [英] Responding to address bar key events in Firefox Add-on

查看:142
本文介绍了响应Firefox插件中的地址栏键事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写一个可以实时获取地址栏内容的Firefox插件,例如,这个插件会将用户每次按下a的每个a改为A。
问题是,我找不到任何方法来做到这一点,有没有办法做到这一点(实时获取地址栏的内容)?


  1. 解决方案

首先,您需要创建一个覆盖主浏览器窗口(browser.xul)的简单扩展。 建立扩展 - MDC URL Fixer - 很好的扩展例子 然后你会需要附加一个事件监听器到URL栏(关键词:addEventListener,events)。尽管您应该阅读有关各种可用事件的文档,但您可能想要听按键。您可以搜索Firefox或其他扩展程序的源代码,以查看它们将侦听程序附加到的元素。您可以在DOM检查器扩展中检查DOM树(查看可用元素)。

  • 在事件侦听器中,您应该检查并更新地点酒吧(gURLBar.value,IIRC)。你还必须做一些事情来保持插入的位置。



  • 不要犹豫,寻求帮助在 https://developer.mozilla.org/en/Extensions 列出的论坛


    I want to write a Firefox addon that could get the content of the address bar in real time, for example this addon will change every "a" to "A" just as the user pressed "a". The problem is that I couldn't find any way to do that in Javascript, is there a way to do it (getting the address bar content in real time)?

    解决方案

    You didn't actually say at what point you're stuck.

    1. First you need to create a simple extension that overlays the main browser window (browser.xul). Building an Extension - MDC, URL Fixer - good example extension

    2. Then you'll need to attach an event listener to the URL bar (key words: addEventListener, events). You'll probably want to listen for "keypress", although you should read the documentation on various events available. You can search through Firefox or other extensions' source to see what element they attach the listener to. You can inspect the DOM tree (to see the elements available) in the DOM inspector extension.

    3. In the event listener you should check and update the URL in the Location Bar (gURLBar.value, IIRC). You'll also have to do something to preserve the caret position.

    Don't hesitate to ask for help in the forums listed at https://developer.mozilla.org/en/Extensions

    这篇关于响应Firefox插件中的地址栏键事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆