今天在看一个discuz的template的时候发现一个没有见过的.htc文件。打开之后发现里面的一些类似于js的函数和定义,也有一些css的东西,顺手百度了下,记录下。

From the stackoverflow

What is difference between .htc and .js file?
For Microsoft Internet Explorer 5 and later, HTML Components (HTCs) provide a mechanism to implement components in script as Dynamic HTML (DHTML) behaviors. An HTC is an HTML file that contains script and a set of HTC-specific elements that define the component. The component is saved with an .htc extension. This section lists these HTC-specific elements and the members they support.

换句话说

1、从 Internet Explorer 5 开始引入了 HTML 组件的概念, HTML 组件也是 Internet Explore 5.5 一个革命性的突破。Microsoft 的目的是用它取代 ActiveX 控件。HTML 组件是封装的对象,也像 ActiveX 控件一样是“自包含”的,可以在开发完后发布给任何人。HTC 文件并不仅仅是将一个 HTML 文件的扩展名换成 .htc,它含有脚本和 HTC 定制元素的集合。

2、在 HTML 文件中,HTC 拥有和页面中其他的 DHTML 元素一样的访问方式。这就意味着所有 HTC 元素都可以通过 id 属性在脚本中调用,也就是说 HTC 元素的属性、方法都可以通过脚本来进行灵活的运用。

以上都不是人话。

其实很简单的总结,.htc的文件是为了对付ie用的的方法,鉴于基本脱离ie,还有让人深恶痛绝的ie6等等。

所以说为毛很少见。

over