I'm trying to find a good way to detect when the window's name has changed. It is easy enough to do with setInterval like this:
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); However, setInterval 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?
Thanks! Joseph Mastey
EDIT:
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 evercookie 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.
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:
window.__defineSetter__("name", function(nm) { console.log("intercepted window.name attempt: "+nm); }); window.__defineGetter__("name", function() { return ""; }); 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.