Today I saw some brothers on the forum that don’t know what HTC is. The young master will talk a little about it here.
Starting from version 5.5, Internet Explorer (IE) has begun to support the concept of Web behavior. These behaviors are described by script files with the suffix .htc, which define a set of methods and properties that programmers can apply to almost any element on an HTML page. Web behaviors are great because they allow programmers to "connect" custom functions to existing elements and controls, rather than having to let users download binary files (such as ActiveX controls) to complete this function. Web behavior is also the recommended way to extend the IE object model and control set. Microsoft provides several customized web behaviors in the DHTML behavior library column on its developer site. I will discuss a relatively new Web behavior in this article: WebService behavior.
Web service is a method that passes parameters and receives return values through an open Simple Object Access Protocol (SOAP) in order to provide interface-independent software services on the Web. There are many examples and articles on the Internet to help you create web services and use these web services from traditional window form-based applications or on the server side, but you can also use WebService behavior or use web services on the client browser.
The benefits of calling a Web service from a client browser include the ability to get faster response time for the server, and the result is to generate pages with stronger interaction capabilities and make users happier. Unlike traditionally sending a form back to the server and then receiving a new page (this process includes re-downloading images and other content), WebService behavior uses XMLHTTP to send and receive only content related to the transaction process in the background, which can then be displayed through DHTML and scripts.
The only browser I know that currently supports web behavior is IE; developers know to avoid features that can only be used on IE. But W3C has this CSS extension in its working draft as a future standard.
If you decide to use Web behavior now, you can use the following JavaScript function to detect whether the client supports this function:
function canUseBehaviors() {
var ua = ;
var msiePos = (’MSIE’);
var msieVer = 0;
var behaviorsAvailable = false;
var iHandle = 0;
if (msiePos >= 0) {
msieMajorVer = parseInt((msiePos + 5));
msieMinorVer = parseInt((msiePos + 7));
if (msieMajorVer >= 5) {
if (((msieMajorVer == 5) && (msieMinorVer >= 5)) ||
(msieMajorVer > 5)) {
behaviorsAvailable = true;
}
}
}
return behaviorsAvailable;
}
Using the above function, you can determine at runtime whether you can use the WebService behavior to call the Web service and use IE's DHTML function to display the results or send this form to the server to complete the necessary operations, and then generate a complete page again. Using CSS syntax to add WebService behavior to an element does not affect browsers that do not support specific CSS properties.
Microsoft provides a good reference for programmers to use it to better be familiar with accessing Web services from clients. Developers can also find the necessary HTML component (*.htc) files on Microsoft's site.
With the WebService behavior in the client toolkit, developers can create richer and more interactive pages for web consumers, which are the same as enterprise users who use Web services provided by large hosts or form window-based applications. This will help eliminate redundant code and enhance the user experience by improving response time for the specific features provided to the service.