检索当前焦点/鼠标悬停的超链接 URL
我正在开发一个扩展,我需要找到一种方法来捕获当前的焦点链接。
当我们按 TAB 键,或将鼠标悬停在超链接上时,我们可以在状态栏(firefox 4+ 的地址栏右侧)中看到该链接的 URL 已显示。
如何在附加在线生成器中使用 Javascript 捕获此 URL?如何将其存储到变量中,并且每当焦点链接更改时,变量值都会相应更新?我在互联网上搜索了几个小时,到目前为止发现了这个名为 Document.activeElement.href 的函数?但我不确定这是否是我需要的,如果是,我该如何使用它?
请帮忙!
谢谢 !!!
I'm working on an extension that I need to find a way to catch the current focused link.
When we hit TAB Key, or mouse over a hyperlink, we can see in the status bar (right side of the address bar for firefox 4+) the URL of that link has been shown.
How do you capture this URL with Javascript in Add-on online builder? how do I store it into a variable and whenever the focused link is changed, the variable value will be updated accordingly? I searched internet for hours and so far found this function called Document.activeElement.href ?? But I'm not sure that's what I need and if it is, how do I use it?
Please help!
Thanks !!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您需要将事件处理程序放在感兴趣的所有链接上,使用jQuery这非常容易,当事件触发时您可以捕获href > 相应的属性和处理
you will need to put event handlers on all links of the interest, this is quite easy using jQuery, when the event trigger you can capture the href attribute and process accordingly
这应该可以解决问题:
如果您不想使用 jQuery,请告诉我,我会重写我的答案。
This should do the trick:
Let me know if you don't want to use jQuery, and I'll re-write my answer.
变量
window.XULBrowserWindow.overLink
恰好包含状态栏中显示的当前悬停 URL,但它不会保存悬停的实际元素。The variable
window.XULBrowserWindow.overLink
happens to contain the current hovered URL as shown in the status bar but it doesn't save the actual element being hovered.http://jsfiddle.net/DmX5j/6/
纯JS方式。不确定这是否是您正在寻找的内容,基本上在焦点或鼠标悬停时当前链接已更新。
http://jsfiddle.net/DmX5j/6/
pure JS way. Not sure if this is what you are looking for or not, basically on focus or mouseover the current link is updated.