Created
October 5, 2010 01:26
-
-
Save esprehn/610797 to your computer and use it in GitHub Desktop.
This file contains 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> | |
<title>Firefox Click Event</title> | |
<a href="http://www.yahoo.com/" onclick="return clickRedirect('google');">Test!</a> | |
<a href="http://www.google.com/" id="google">Google.com</a> | |
<script> | |
/** | |
* Redirect a click to another element. | |
* | |
* @return false | |
*/ | |
function clickRedirect(id) { | |
document.getElementById(id).click(); | |
return false; | |
} | |
/** | |
* Provide click events for all DOM elements instead of just form elements | |
*/ | |
HTMLElement.prototype.click = function() { | |
var evt = document.createEvent('MouseEvents'); | |
evt.initMouseEvent('click', true, true, window, 1, 0, 0, 0, 0, false, false, false, false, 0, null); | |
if (this.dispatchEvent(evt)) { | |
// Firefox doesn't navigate automatically, so lets do that here | |
if (this.nodeName.toUpperCase() === "A" && this.href) { | |
window.location.href = this.href; | |
} | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment