var runPrefixMethod = function (element, method) {
var usablePrefixMethod;
["webkit", "moz", "ms", "o", ""].forEach(function (prefix) {
if (usablePrefixMethod) return;
if (prefix === "") {
// 无前缀,方法首字母小写
method = method.slice(0, 1).toLowerCase() + method.slice(1);
}
var typePrefixMethod = typeof element[prefix + method];
if (typePrefixMethod + "" !== "undefined") {
if (typePrefixMethod === "function") {
usablePrefixMethod = element[prefix + method]();
} else {
usablePrefixMethod = element[prefix + method];
}
}
}
);
return usablePrefixMethod;
};
调用方式
<div class="schedule" id="schedule" onclick="runPrefixMethod(this,'RequestFullScreen')"></div>