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.
精彩评论