开发者

How to capture change on page title from a Firefox extension

Is there a way to capture when a website ti开发者_StackOverflow中文版tle 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>


There is a DOMTitleChanged event.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜