How to capture change on page title from a Firefox extension

微笑、不失礼 提交于 2019-12-05 04:06:41

问题


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


回答1:


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>



回答2:


There is a DOMTitleChanged event.



来源:https://stackoverflow.com/questions/4136453/how-to-capture-change-on-page-title-from-a-firefox-extension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!