3

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

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
gtilx
  • 2,055
  • 4
  • 17
  • 21
  • What exactly do you mean? Do you mean changes of the title between two visits? – Felix Kling Nov 09 '10 at 17:21
  • 1
    No, I mean when the title of a website changes without refreshing or anything like that. Like what happens with google instant search. – gtilx Nov 09 '10 at 18:50

2 Answers2

3

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>
Dr.Molle
  • 116,463
  • 16
  • 195
  • 201
1

There is a DOMTitleChanged event.

skomorokh
  • 23
  • 4