一些我以前没见过的新代码 [英] Some new code I have not seen before

查看:47
本文介绍了一些我以前没见过的新代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




这里有一些我在WikiPedia中使用之前没见过的新代码


< ! - [if lt IE 6]>

< style type =" text / css" media =" screen"

...

< / style>

<![endif] - >


<! - [if IE 6]>

< style type =" text / css" media =" screen"

...

< / style>

<![endif] - >


它有用吗?

它有多便携?

旧浏览器怎么样?

还有101个问题:)


这里的WikiPedias: -


<! - [if lt IE 5.5000]> < style type =" text / css"> @import

" /skins-1.5/monobook/IE50Fixes.css" ;;< / style><![endif] - >

<! - [if IE 5.5000]>< style type =" text / css"> @import

" / skin- 1.5 / monobook / IE55Fixes.css" ;;< / style><![endif] - >

<! - [if gte IE 6]>< style type = " text / css"> @import

" /skins-1.5/monobook/IE60Fixes.css" ;;< / style><![endif] - >

<! - [if IE]>< script type =" text / javascript"

src =" /skins-1.5/common/IEFixes.js" >< / script>


Aaron

Hi,

Here''s some new code I have not seen before it is used in WikiPedia as well

<!--[if lt IE 6]>
<style type="text/css" media="screen">
...
</style>
<![endif]-->

<!--[if IE 6]>
<style type="text/css" media="screen">
...
</style>
<![endif]-->

Does it work ?
How portable is it ?
What about old browsers ?
And 101 other questions :)

Here''s WikiPedias :-

<!--[if lt IE 5.5000]><style type="text/css">@import
"/skins-1.5/monobook/IE50Fixes.css";</style><![endif]-->
<!--[if IE 5.5000]><style type="text/css">@import
"/skins-1.5/monobook/IE55Fixes.css";</style><![endif]-->
<!--[if gte IE 6]><style type="text/css">@import
"/skins-1.5/monobook/IE60Fixes.css";</style><![endif]-->
<!--[if IE]><script type="text/javascript"
src="/skins-1.5/common/IEFixes.js"></script>

Aaron

推荐答案

Aaron Gray写道:
Aaron Gray wrote:
这里有一些我在WikiPedia中使用之前没见过的新代码


<! - [如果是IE 6]>
< style type =" text / css" media =" screen"
...
< / style>
<![endif] - >

<! - - [if IE 6]>
< style type =" text / css" media =" screen"
...
< / style>
<![endif] - >

是否有效?
[...]
Here''s some new code I have not seen before it is used in WikiPedia as
well

<!--[if lt IE 6]>
<style type="text/css" media="screen">
...
</style>
<![endif]-->

<!--[if IE 6]>
<style type="text/css" media="screen">
...
</style>
<![endif]-->

Does it work ?
[...]




是的,这里完全偏离主题。

PointedEars



Yes, and it is completely off-topic here.
PointedEars




Aaron Gray写道:

Aaron Gray wrote:


这里有一些我没有的新代码之前看到它在WikiPedia中使用

<! - [if lt IE 6]>
< style type =" text / css" media =" screen"
...
< / style>
<![endif] - >

<! - - [if IE 6]>
< style type =" text / css" media =" screen"
...
< / style>
<![endif] - >

是否有效?
它的可移植性如何?
旧版浏览器怎么样?
还有101个问题:)
Hi,

Here''s some new code I have not seen before it is used in WikiPedia as well

<!--[if lt IE 6]>
<style type="text/css" media="screen">
...
</style>
<![endif]-->

<!--[if IE 6]>
<style type="text/css" media="screen">
...
</style>
<![endif]-->

Does it work ?
How portable is it ?
What about old browsers ?
And 101 other questions :)




这就是所谓的 ;条件评论并且它们被介绍并且由Internet Explorer支持


< http://msdn.microsoft.com/library/default.asp?url = / workshop / author /dhtml/overview/ccomment_ovw.asp>


但它对所有浏览器的制作方式都很有用。这是我测试页面模板中代码的



<! - [如果是IE 5]>

< p>

< var onclick =" testIE()">测试IE< / var>

< / p>

<![endif] - >

<![如果! gte IE 5]>

< p>

< var onclick =" testGK()">测试GK< / var>

< / p>

<![endif]>


如果浏览器是Internet Explorer 4.x或更高版本,它可以理解

条件评论并正确解析。因此,如果它的版本是5.0

或更高 - [如果是gte IE 5]它会显示

< var onclick =" testIE()">测试IE< / var>

否则显示

< var onclick =" testGK()">测试GK< / var>


如果它是另一个没有条件评论支持的浏览器(Firefox for

例子)它只是跳过第一个块,因为它看起来就像是

regular<! - ... - > HTML评论并显示

< var onclick =" testGK()">测试GK< / var>

类似的方法但是对于JavaScript代码是由Microsoft实现的条件编译中的


< http://msdn.microsoft.com/ library / default.asp?url = / library / en-us / script56 / html / js56jsconconditionalcompilation.asp>


这是一个来自我的对象调度程序的块:取决于

什么浏览器和脚本运行的平台,不同的

构造函数被称为:


/ **

*调度对象请求并在需要时降级

* /

/ * @ cc_on

@if(@_ mac)

this.error.code = 1;

this.error.message =''此平台不支持ActiveX。'';

@elif (@ _win32&&(@_ jscript_version< 5))

this.error.code = 2;

this.error.message = ''JScript引擎版本太低了。'';

@elif(@ _win32&& (@_jscript_version> = 5))

jsFileManager_IE.call(this,mode);

@else @ * /

if(typeof) (netscape)==''对象''){

jsFileManager_GK.call(这个,模式);

}

else {

this.error.code = 3;

this.error.message =''这个

平台不支持XPConnect。''; < br $>
}

/ * @ end @ * /

}


美丽的是,这是有效的根据需要有或没有条件

编译支持。



That''s called "conditional comments" and they are introduced and
supported by Internet Explorer:
<http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/overview/ccomment_ovw.asp>

But it works just great for all browsers in the way it''s made. Here''s
the code from my test page template:

<!--[if gte IE 5]>
<p>
<var onclick="testIE()">Test IE</var>
</p>
<![endif]-->
<![if ! gte IE 5]>
<p>
<var onclick="testGK()">Test GK</var>
</p>
<![endif]>

If browser is Internet Explorer 4.x or higher it understands the
conditional comments and parses it properly. So if it''s version is 5.0
or higher - [if gte IE 5] it displays
<var onclick="testIE()">Test IE</var>
otherwise it displays
<var onclick="testGK()">Test GK</var>

If it''s another browser w/o conditional comments support (Firefox for
example) it simply skips the first block because it looks just like
regular <!-- ... --> HTML comment and it displays
<var onclick="testGK()">Test GK</var>
which is still exactly what we wanted.
A similar approach but for JavaScript code is implemented by Microsoft
in conditional compilation:
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/js56jsconconditionalcompilation.asp>

Here is for example a block from my object dispatcher: depending on
what browser and what platform the script is running on, different
constructors are called:

/**
* Dispatching object request and degrade if needed
*/
/*@cc_on
@if (@_mac)
this.error.code = 1;
this.error.message = ''ActiveX is not supported on this platform.'';
@elif (@_win32 && (@_jscript_version < 5))
this.error.code = 2;
this.error.message = ''JScript engine version is too low.'';
@elif (@_win32 && (@_jscript_version >= 5))
jsFileManager_IE.call(this,mode);
@else @*/
if (typeof(netscape) == ''object'') {
jsFileManager_GK.call(this,mode);
}
else {
this.error.code = 3;
this.error.message = ''XPConnect is not supported on this
platform.'';
}
/*@end @*/
}

The beauty is that this works as needed with or without conditional
compilation support.




Aaron Gray写道:

Aaron Gray wrote:


这里有一些我在WikiPedia中使用之前没见过的新代码

<! - [if lt IE 6]>
< style type =" text / css" media =" screen"
...
< / style>
<![endif] - >

<! - - [if IE 6]>
< style type =" text / css" media =" screen"
...
< / style>
<![endif] - >

是否有效?
它的可移植性如何?
旧浏览器怎么样?
Hi,

Here''s some new code I have not seen before it is used in WikiPedia as well

<!--[if lt IE 6]>
<style type="text/css" media="screen">
...
</style>
<![endif]-->

<!--[if IE 6]>
<style type="text/css" media="screen">
...
</style>
<![endif]-->

Does it work ?
How portable is it ?
What about old browsers ?




这些是Microsoft条件注释。请注意,它们只是按照通常的W3C

标准进行评论,对于大多数浏览器来说只是

作为常规html评论。但是,IE浏览器(至少是最近的

)是为了在评论中看到的,例如你所引用的那样,并且

注释中的代码需要什么。请注意,当IE的代码完成时,一个开始

条件注释必须与结束条件注释匹配

。这些有条件的评论似乎很好地工作了。使用

脚本检测IE浏览器非常困难,因为其他浏览器有时会欺骗它们。因此,只有在IE浏览器上你必须做一些

时,IE

条件注释才有用。这些条件评论中有几条。我在某个地方有一张桌子,但我现在似乎无法找到它。



These are Microsoft conditional comments. Notice that they appear just
as regular html comments to most browsers following the usual W3C
standards for comments. However, IE browsers(at least the more recent
ones) are designed to see within a comment such as quoted by you and do
what the code within the comment requires. Notice that a start
conditional comment has to be matched by an end conditional comment
when the code for IE only is finished. These conditional comments seem
to work fairly well. It is very difficult to detect IE browsers using
script, because other browsers sometimes spoof them. Thus the IE
conditional comment can be of some use when you have to do something
only on IE browsers. There are several of these conditional comments. I
have a table of them somewhere, but I can not seem to find it just now.


这篇关于一些我以前没见过的新代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆