|
To access the contents, click the chapter and section titles.
Platinum Edition Using HTML 4, XML, and Java 1.2
Interfacing with ActiveX Controls with JavaScriptThis is an example of using JScript, Microsofts implementation of the JavaScript language, to manipulate another Web browser object, ActiveX Controlsin this case the ActiveX Label Control. ActiveX Controls are a Microsoft technology, similar to plug-ins, that enables developers to dynamically increase the capabilities of the Web browser. Many major software developers that produce plug-ins for Netscape Navigator produce ActiveX Control versions as well. Therefore, controlling ActiveX Controls would be done for many of the same reasons as for plug-ins. The Label Control enables the Web author to place text on the Web page, select the text, font, size, and an arbitrary angle of rotation. One of the exciting things about the Label Control is that it can be manipulated in real-time, producing a variety of automated or user-controlled effects. In the following example, the Label Control is used to place text on the Web page, and form input is used to enable the user to change the text used and the angle at which it is displayed. Figure 23.8 shows the default configuration of the label and Figure 23.9 shows it after the text and the rotation angle have been changed.
Listing 23.5 shows the code used to produce this example. The following are some things to note about the example:
Listing 23.5 Object.htmJavaScript Can Interact with Objects <HTML> <HEAD> <SCRIPT LANGUAGE=JAVASCRIPT> <!-- Hide this script from incompatible Web browsers --> function ChangeIt() { lblActiveLbl.caption = document.LabelControls.txtNewText.value } function RotateP() { lblActiveLbl.angle = lblActiveLbl.angle + 5 document.LabelControls.sngAngle.value = lblActiveLbl.angle } function RotateM(){ lblActiveLbl.Angle = lblActiveLbl.Angle - 5 document.LabelControls.sngAngle.value = lblActiveLbl.angle } // Hide this script from incompatible Web browsers --> </SCRIPT> <TITLE>JavaScript and Object Manipulation</TITLE> </HEAD> <BODY BGCOLOR=#FFFFFF> <H1>JavaScript and Object Manipulation</H1> <HR> <OBJECT classid=clsid:99B42120-6EC7-11CF-A6C7-00AA00A47DD2 id=lblActiveLbl width=250 height=250 align=left hspace=20 vspace=0 > <PARAM NAME=Angle VALUE=0> <PARAM NAME=Alignment VALUE=4> <PARAM NAME=BackStyle VALUE=0> <PARAM NAME=Caption VALUE=A Sample Label> <PARAM NAME=FontName VALUE=Arial> <PARAM NAME=FontSize VALUE=20> <PARAM NAME=FontBold VALUE=1> <PARAM NAME=ForeColor VALUE=0> </OBJECT> <FORM NAME=LabelControls> <TABLE> <TR><TD><INPUT TYPE=TEXT NAME=txtNewText SIZE=25></TD> <TD><INPUT TYPE=BUTTON NAME=cmdChangeIt VALUE=Change Text onClick=ChangeIt()> </TD></TR> <TR><TD><INPUT TYPE=TEXT NAME=sngAngle SIZE=5></TD> <TD><INPUT TYPE=BUTTON NAME=cmdRotateP VALUE=Rotate Label + 5 onClick=RotateP()> </TD></TR> <TR><TD></TD> <TD><INPUT TYPE=BUTTON NAME=cmdRotateM VALUE=Rotate Label - 5 onClick=RotateM()> </TD></TR> </TABLE> </FORM> <SCRIPT LANGUAGE=JAVASCRIPT> <!-- Hide this script from incompatible Web browsers --> document.LabelControls.sngAngle.value = lblActiveLbl.angle document.LabelControls.txtNewText.value = lblActiveLbl.caption // Hide this script from incompatible Web browsers --> </SCRIPT> <HR> <ADDRESS> Jim ODonnell, <A HREF=mailto:odonnj@rpi.edu>odonnj@rpi.edu</A> </ADDRESS> </BODY> </HTML>
|
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement. |