我正在尝试实现类似于这个的功能...
if (window.onblur) {
setTimeout(function () {
DTitChange(name)
}, 1000)
} else {
document.title = dtit
}
窗口的onblur事件似乎无法正常工作,有什么可以替代它的吗?
我正在尝试实现类似于这个的功能...
if (window.onblur) {
setTimeout(function () {
DTitChange(name)
}, 1000)
} else {
document.title = dtit
}
If there's an onblur event handler:
execute DTitChange once ever second.
Else
document.title = dtit
这可能不是你想要的。请尝试
window.onblur = function () {
setTimeout(function () { DTitChange(name) }, 1000);
};
window.onblur
分配一个函数,在你的问题中,你只是测试属性onblur
是否存在。但是window.onblur
在每个浏览器中并不总是能够正确工作。文章检测浏览器窗口的焦点展示了如何设置这个功能。在你的情况下,代码应该是这样的:function DTitBlur() {
/* change title of page to ‘name’ */
setTimeout(function () {
DTitChange(name)
}, 1000);
}
function DTitFocus() {
/* set title of page to previous value */
}
if (/*@cc_on!@*/false) { // check for Internet Explorer
document.onfocusin = DTitFocus;
document.onfocusout = DTitBlur;
} else {
window.onfocus = DTitFocus;
window.onblur = DTitBlur;
}