HTML Components is one of the main extensions of IE5.0. It is also the most revolutionary, Microsoft's intentions use HTML components to replace ActiveX controls, like Active controls, HTML components are self-sustainable enclosed objects, can be once Develop any use, there are many benefits to using the HTML components, this article will reveal some of them!
The HTML component has brought a lot of new terms, ideas, objects, methods, and properties. I will accept these through a calendar application, this calendar application shows the current month, the current date is displayed, and the current date is displayed.
==== HTML behavior and HTC behavior ===
The HTML component encapsulates HTML content and can be inserted into other HTML documents. Before the HTML component, the only way to use custom control in the HMTL document is to use Microsoft ActiveX controls. One of the shortcomings of ActiveX controls is that the client must install HTML control before use, and on the other hand download the main page to the client. For DHTML's authors, HTML controls are more attractive because they can develop their own controls and components in the language they are familiar with, and HTC provides a simple mechanism to implement DHTML behavior in the script. An HTC file and HTML file do not have any difference, and ".htc" is a suffix, which includes scripts and a series of HTC custom description elements that define the properties, methods, events, etc. of HTML components, all HTC elements pass objects. The id attribute is used as an object in the script, and all methods and properties can be dynamically operated in the script.
You can use HTC to implement the following behavior:
* Set the properties and methods. Definition through "Property" and "Method" element
* Setting a custom event. Implement the "Event" element, "Fire ()" method is used to release the event,
Set the event environment via the "CreateEventObject () method.
* Access the DHTML object model of the HTML page that contains the HTC, use the HTC's "Element" object, return
An additional behavior element, using this object, HTC can access the object model (attributes, methods, events) that contains the text and its object model (attribute, method, event).
* Take a notification, implement the "attach" element, the browser not only informs the HTC standard DHTML event, but also
Know HTC two special events: OnContentReady events and the onDocumentReady event.
HTC encapsulates the definition of behavior. The first appearance of behavior is in IE5.0. The advanced behavior package in HTC is inhane and elemental mark separation. In IE5.0, the behavior in the script can be separated from the elements. Out, in IE5.5, the element cannot be separated from its original behavior.
=== Define the tag and namespace ===
The basis of HTC is custom tag, and the first appearance of custom tags is in IE5.0, which allows the Web author to define a textbook structure through a series of styles associated with the structure, for example: You can define a new tag.
@Media all {
DOCJS /: Right {text-align: right; width: 100}
}
Style>
HEAD>
Read Doc JavaScript's Column, Tips, Tools, and Tutorials DOCJS: Right>
Body>
Html>
In Internet Explorer, you want to define custom tags for the page, you must provide namespaces for this tag, and custom tags are XML namespaces based on XML symbols, as shown below. We use DOCJS namespace:
XMLNs is an abbreviation for XML NameSpace. I define a custom tag called Right. To use this tag, you must add the correct XML namespace prefix before the tag: DOCJS: Right, if the namespace is not defined, the document parsing When the custom tag is handled as an unknown marker although there is an unknown mark, it does not cause errors, not affecting the other tag, and there is no behavior to be applied there, you can define multiple namespaces in a single HTML tag. :
=== The top page ===
Now let's turn our focus to our calendar application example, which includes 4 different pages, canlendar.html is the top HTML document, which contains Calendar.htc HTC, and canlendar.htc has in turn contain two other things HTC: day.htc and today.htc, calendar.html
The content is as follows:
Import namespace = "mycal" Implementation = "Calendar.htc" />
HEAD>
Click a day in the calendar to add or modify your schedule. P>
Body>
Html>
There are several points, you must focus: First, namespace definitions in the tag, we need to use the namespace defined in the HTC we want to call, in the canlendar.htc namespace is: Mycal, so The XMLNS ID must appear in the tag.
IMPORT> Tags Started by Questions and other normal tags, which requires the browser to import the specified HTC: Calendar.htc, HTC can have multiple namespaces, so you need to specify the namespace to use when importing (MyCal):
Import namespace = "mycal" Implementation = "Calendar.htc" />
One of the main advantages of HTC is that the browser will have been resoluntary until the input file is imported. The asynchronous mechanism for page processing will result in many problems, and the browser does not have the elements that have been fully displayed to start the parsing page. As an example, you can create an object, and access a method at the bottom of the page at the top of the text, if the object is Some reasons are ready, you will get an error indication that there is no way to do or does not support you to access the method, I believe that you have already encountered such a thing! No matter what this is the case, IMPORT is synchronized, and the browser will wait for the page to import and ready. The only page of the page and the important line is to call the custom tag MyCal: Calendar:
Because the page has been imported, the call will create a calendar like it is specified in Calendar.htc.
Computer World Developer Club
http://www.dev-club.com