这段 IE 特定代码的作用是什么?
What does this IE specific code do?
我在看 an article on how to detect focus in a browser window. Here's the demo page。
我对这个条件的作用感到困惑。
if (/*@cc_on!@*/false) { // check for Internet Explorer
document.onfocusin = onFocus;
document.onfocusout = onBlur;
} else {
window.onfocus = onFocus;
window.onblur = onBlur;
}
我假设 document.onfocusin
是 window.onfocus
的 Internet Explorer 等价物。但是我不明白条件是做什么的:
if (/*@cc_on!@*/false) { // check for Internet Explorer
这不就是注释,把表达式简化为if(false)
吗?
根据 this link,@cc_on
语句允许 IE 呈现其他浏览器无法呈现的内容。他们称之为“条件编译”。
It is strongly recommended that you use the @cc_on statement in a comment, so that browsers that do not support conditional compilation will accept your script as valid syntax:
An @if or @set statement outside of a comment also activates conditional compilation.
因此,IE 会将您的代码的第一个条件读取为 !false
,但所有其他浏览器都会将其读取为 false
。
但是警告:
Conditional compilation is not supported in Internet Explorer 11 Standards mode and Windows Store apps.
我在看 an article on how to detect focus in a browser window. Here's the demo page。
我对这个条件的作用感到困惑。
if (/*@cc_on!@*/false) { // check for Internet Explorer
document.onfocusin = onFocus;
document.onfocusout = onBlur;
} else {
window.onfocus = onFocus;
window.onblur = onBlur;
}
我假设 document.onfocusin
是 window.onfocus
的 Internet Explorer 等价物。但是我不明白条件是做什么的:
if (/*@cc_on!@*/false) { // check for Internet Explorer
这不就是注释,把表达式简化为if(false)
吗?
根据 this link,@cc_on
语句允许 IE 呈现其他浏览器无法呈现的内容。他们称之为“条件编译”。
It is strongly recommended that you use the @cc_on statement in a comment, so that browsers that do not support conditional compilation will accept your script as valid syntax:
An @if or @set statement outside of a comment also activates conditional compilation.
因此,IE 会将您的代码的第一个条件读取为 !false
,但所有其他浏览器都会将其读取为 false
。
但是警告:
Conditional compilation is not supported in Internet Explorer 11 Standards mode and Windows Store apps.