如何从Firefox扩展名捕获页面标题上的更改 [英] How to capture change on page title from a firefox extension

查看:134
本文介绍了如何从Firefox扩展名捕获页面标题上的更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

解决方案

我不知道,如果它从Firefox扩展名起作用,但是在文档中可以使用,我认为它也可以从扩展名中使用。



您必须使用,特别是DOMSubtreeModified,http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-MutationEventrel =nofollow>。



一个小的示例脚本,放在< title />

 < script type =text / javascript> 
<! -
(function()
{
var _this = {
target:document.getElementsByTagName('TITLE')[0],
oldValue:document.title
};
_this.onChange = function()
{
if(_this.oldValue!== document.title)
{
_this.oldValue = document.title;
alert('somebody change the title');
}
};
_this.delay = function()
{
setTimeout(_this.onChange,1);
};
_this.target.addEventListener('DOMSubtreeModified',_ this.delay,false)
})()
// - >
< / script>


Is there a way to capture when a website title changes from a firefox extension?

解决方案

I don't know, if it works from a firefox extension, but as it works in a document, I think it works from a extension too.

You have to work with Mutation-Events, especially DOMSubtreeModified. This fires on every change on the target.

A little example-script, put it somewhere after the <title/>

<script type="text/javascript">
<!--
(function()
  {
    var _this={
                target:document.getElementsByTagName('TITLE')[0],
                oldValue:document.title
              };
    _this.onChange=function()
                  {
                    if(_this.oldValue!==document.title)
                    {
                      _this.oldValue=document.title;
                      alert('somebody changed the title');
                    }
                 };
    _this.delay=function()
                {
                  setTimeout(_this.onChange,1);
                };
    _this.target.addEventListener('DOMSubtreeModified',_this.delay,false)
  })()
//-->
</script>

这篇关于如何从Firefox扩展名捕获页面标题上的更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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