Created
October 18, 2011 05:45
-
-
Save froop/1294701 to your computer and use it in GitHub Desktop.
[JavaScript] イベント登録、発行ユーティリティ
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
function addEvent(target, type, listener) { | |
if (target.addEventListener) { // W3C | |
target.addEventListener(type, listener, false); | |
} else if (target.attachEvent) { // IE | |
target.attachEvent("on" + type, listener); | |
} else { | |
target["on" + type] = listener; | |
} | |
} | |
function dispatchMouseEvent(target, type) { | |
var event; | |
if (target.dispatchEvent) { // W3C | |
event = document.createEvent("MouseEvents"); | |
event.initEvent(type, false, true); | |
target.dispatchEvent(event); | |
} else if (target.fireEvent) { // IE | |
target.fireEvent("on" + type); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment