How to listen for changes to the title element?

后端 未结 4 1861
渐次进展
渐次进展 2020-12-01 05:18

In Javascript, is there a technique to listen for changes to the title element?

4条回答
  •  爱一瞬间的悲伤
    2020-12-01 06:05

    There's not a built-in event. However, you could use setInterval to accomplish this:

    var oldTitle = document.title;
    window.setInterval(function()
    {
        if (document.title !== oldTitle)
        {
            //title has changed - do something
        }
        oldTitle = document.title;
    }, 100); //check every 100ms
    

提交回复
热议问题