What is difference between .htc and .js file?

旧街凉风 提交于 2019-11-28 16:39:24

问题


What is difference between .htc and .js file? Can we convert any .htc file to a .js file?

The problem is if we use htc to make png fixes, then we add htc to css file using

body { behavior: url("csshover3.htc"); } 

But this is not W3C valid, so want to convert the .htc to .js and then use as a js file to attach in so it will be W3C valid.

Can anyone tell me how to convert and use any .htc file as JavaScript file?


回答1:


Technically, you can use conditional comments to allow the code to validate.

http://msdn.microsoft.com/en-us/library/ms537512%28VS.85%29.aspx

A hack is a hack, it's just weird that MS made this hack in a way that it's a valid hack.

Now, something else to consider - are you using a JavaScript library? Then you should be using the library to do this functionality, which would eliminate the need for the HTC (which needs JavaScript enabled to run).




回答2:


From the Microsoft HTC Reference🕗:

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.

Therefore, they are not just javascript .js files, they also contain a set of HTC-specific elements.

Edit:

Concerning the conversion from .htc to .js, I'm not sure if it can be done directly, but I've come across this set of .js tools to address the same issues that .htc files are trying to fix in IE.




回答3:


A htc-file is a behaviour-file, have a look at MSDN🕗, W3C🕗 and here🕗. In a htc-file you can embed HTML-Code as well as Script-Code. Since a htc-file is not a pure Javascript-File, you cannot just convert it, but you may extract the Javascript-Parts of it, if you need.

Most HTC-Files I have seen so far are there to fix Internet Explorer problems, e.g. PNG transparency, which shows the sense of the htc-files: They can attach foreign properties to HTML-Elements, in this case, transparency.



来源:https://stackoverflow.com/questions/1617667/what-is-difference-between-htc-and-js-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!