If Crockford used it in production though, the alert() would be removed there, right? So someone could still in theory hotlink that.
if (location.host.search(/crockford.com$/i) != -1) {
alert("Stop hotlinking me!")
}
I don't think you can fool that, but I'd love to hear about how I'm wrong. if (location.host.search(/crockford.com$/i) != -1) {
throw "Stop hotlinking me!";
}And even then, this can bypass it:
var temp = String.prototype.search;
String.prototype.search = function() { return 0};
if (location.host.search(/crockford.com$/i) != 0) {
throw "Stop hotlinking me!";
}
String.prototype.search = temp;
Though that may cause other problems. var expectedHost = "crockford.com";
if (expectedHost.length !== location.host)
throw "Stop hotlinking me!";
for (var i = 0; i < expectedHost.length; i++)
if (location.host[i] === expectedHost[i])
throw "Stop hotlinking me!";
(though it string[x] might not work in every browser)So thanks for further demonstrating my point!
But really, just check the referrer header.