Created
January 2, 2015 09:09
-
-
Save ihsanberahim/7497cbe82e57084c8d5e to your computer and use it in GitHub Desktop.
// source http://jsbin.com/sosegexego
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<p>Please download this jsbin file to make sure it is works</p> | |
<a href="http://google.com">Google</a> | |
<script id="jsbin-javascript"> | |
var links = document.querySelectorAll('a'); | |
var onClick = function() | |
{ | |
/* | |
Do something; | |
this.source | |
this.details.link | |
*/ | |
console.log(this.source); | |
console.log(this.details.link); | |
}; | |
console.log(links); | |
var key = 0; | |
while(key < links.length) | |
{ | |
var link = links[key].getAttribute('href'); | |
//Disable click | |
links[key].setAttribute('onclick','return false;'); | |
//Bind click callback | |
links[key].addEventListener('click',onClick.bind({ | |
source: links[key], | |
details: { | |
link: link | |
} | |
})); | |
console.log(link); | |
key++; | |
} | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">var links = document.querySelectorAll('a'); | |
var onClick = function() | |
{ | |
/* | |
Do something; | |
this.source | |
this.details.link | |
*/ | |
console.log(this.source); | |
console.log(this.details.link); | |
}; | |
console.log(links); | |
var key = 0; | |
while(key < links.length) | |
{ | |
var link = links[key].getAttribute('href'); | |
//Disable click | |
links[key].setAttribute('onclick','return false;'); | |
//Bind click callback | |
links[key].addEventListener('click',onClick.bind({ | |
source: links[key], | |
details: { | |
link: link | |
} | |
})); | |
console.log(link); | |
key++; | |
} | |
</script></body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var links = document.querySelectorAll('a'); | |
var onClick = function() | |
{ | |
/* | |
Do something; | |
this.source | |
this.details.link | |
*/ | |
console.log(this.source); | |
console.log(this.details.link); | |
}; | |
console.log(links); | |
var key = 0; | |
while(key < links.length) | |
{ | |
var link = links[key].getAttribute('href'); | |
//Disable click | |
links[key].setAttribute('onclick','return false;'); | |
//Bind click callback | |
links[key].addEventListener('click',onClick.bind({ | |
source: links[key], | |
details: { | |
link: link | |
} | |
})); | |
console.log(link); | |
key++; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment