Skip to content

Instantly share code, notes, and snippets.

@RyoSugimoto
Created April 22, 2015 00:56
Show Gist options
  • Save RyoSugimoto/f6dcef3765e934497b60 to your computer and use it in GitHub Desktop.
Save RyoSugimoto/f6dcef3765e934497b60 to your computer and use it in GitHub Desktop.
デフォルトイベントとバブリングの抑制(旧IE対応)。
var cancelBubble,
cancelEvent;
cancelBubble = (function () {
var func = function () {};
if (typeof Event !== 'undefined' && typeof Event.prototype.stopPropagation === 'function') {
func = function (e) { e.stopPropagation(); };
} else if (window.event) {
func = function () { window.event.cancelBubble = true; };
}
return func;
}());
cancelEvent = (function () {
var func = function () {};
if (typeof Event !== 'undefined' && typeof Event.prototype.preventDefault === 'function') {
func = function (e) { e.preventDefault(); };
} else if (window.event) {
func = function () { window.event.returnValue = false; };
}
return func;
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment