detect change to window.name
<p>I'm trying to find a good way to detect when the window's name has changed. It is easy enough to do with <code>setInterval</code> like this:</p>

<pre><code>var old_name = window.name;
var check_name = function() {
    if(window.name != old_name) {
        console.log("window name changed to "+window.name);
        old_name = window.name;
    }
}
setInterval(check_name, 1000);
</code></pre>

<p>However, <code>setInterval</code> is more than a little hacky and may come with a significant (1s in this case) time delay before detecting changes. Is there any kind of event or clever bit of JS that can fire a function when the window name changes?</p>

<p>Thanks!
Joseph Mastey</p>

<hr>

<p>EDIT:</p>

<p>Unfortunately, I don't have control over the code that will be changing the window name, which is in a way the entire point of the exercise. Having looked at <a href="http://samy.pl/evercookie" rel="nofollow">evercookie</a> and other posts about storing data in the window name as a way to track users, I've decided that this isn't really acceptable to me. So, I'm creating a Greasemonkey script (actually, the Chromium version of a greasemonkey script) to prevent this sort of data leakage.</p>

<p>As an aside, I did find some magic functionality that Chromium implements that goes a long way towards what I want. JS provides magic getters and setters that can be used like this:</p>

<pre><code>window.__defineSetter__("name", function(nm) { console.log("intercepted window.name attempt: "+nm); });
window.__defineGetter__("name", function() { return ""; }); 
</code></pre>

<p>If I run this on the console, I can successfully hijack sets of the window name. However, running this code as a Chromium script (at least any variant I've tried so far) does not seem to be able to override the window behavior.</p>
