JSFiddle - React, Tailwind, and code Playground
HTML
<a href="javascript:log(++i);">OOO</a><br/>
<a href="http://codepad.viper-7.com/dRwtne.php53">Referrer check</a>
Test: delayed click: <input type="text" id="secs" /><br />
<textarea id="log">Quick demo for Firefox and Chrome</textarea>
CSS
html,body{height:100%;}
#secs {
width: 4em;
padding: 5px;
text-align: center;
}
#log {
white-space: pre;
font-family: monospace;
font-size: 15px;
height: 80%;
width: 95%;
border: 1px solid #555;
padding: 5px;
}
JavaScript
var i = 0, j=0, secs = 4;
window.onload = function(){
var s=document.getElementById('secs');
s.onkeyup = function() {
var draft = parseFloat(this.value);
if (!isNaN(draft)) {
secs = draft;
this.style.backgroundColor = '';
} else {
this.style.backgroundColor = 'pink';
}
};
s.value = secs;
var isWebkit = document.createElement("a");
isWebkit.style.cssText = "-webkit-border-radius:1px;";
isWebkit = isWebkit.style.cssText.indexOf("radius") !== -1;
if (isWebkit) chromeMethod();
else firefoxMethod();
function chromeMethod() {
// Create a data-URI, redirection by <meta http-equiv=refresh content="0;url=..">
function doNotTrack(url) {
// As short as possible. " can potentially break the <meta content> attribute,
// # breaks the data-URI. So, escape both characters.
var url = url.replace(/"/g,'%22').replace(/#/g,'%23');
// In case the server does not respond, or if one wants to bookmark the page,
// also include an anchor. Strictly, only <meta ... > is needed.
url = '<title>Redirect</title>'
+ '<a href="' +url+ '" style="color:blue">' +url+ '</a>'
+ '<meta http-equiv=refresh content="0;url=' +url+ '">';
return 'data:text/html,' + url;
}
function hideRefer(e) {
var a = e.target;
if (a && a.tagName !== 'A') a = a.parentNode;
if (a && a.tagName === 'A') {
if (e.type == 'contextmenu' || e.button < 2) {
var realHref = a.href; // Remember original URI
// Replaces href attribute with data-URI
a.href = doNotTrack(a.href);
// Restore the URI, as soon as possible
setTimeout(function() {a.href = realHref;}, 4);
}
}
}
...