Skip to content

Instantly share code, notes, and snippets.

@shergin
Created October 23, 2012 12:08
Show Gist options
  • Save shergin/3938422 to your computer and use it in GitHub Desktop.
Save shergin/3938422 to your computer and use it in GitHub Desktop.
javascript protocol
<a href="#" onclick="return onLinkClick(this)" link="http://softline.ru">SoftLine</a>
window.addEventListener('onload', onLoad, false);
function onLoad() {
var nodes = document.getElementsByTagName('a');
for (var i = nodes.length; i--;) {
var node = nodes[i];
var link = node.getAttribute('link');
if (link) {
node.setAttribute('href', link);
node.removeAttribute('onclick');
}
}
}
function onLinkClick(node) {
var link = node.getAttribute("link");
if (link) {
node.setAttribute("href", link);
node.removeAttribute('onclick');
window.location.href = link;
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment