Skip to content

Instantly share code, notes, and snippets.

@esprehn
Created October 5, 2010 01:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save esprehn/610797 to your computer and use it in GitHub Desktop.
Save esprehn/610797 to your computer and use it in GitHub Desktop.
<!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