This article may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist. To maintain the flow of the article, we've left these URLs in the text, but disabled the links.


MIND


GEEK

Robert Hess

GEEK I am developing Web pages that use ActiveX® buttons instead of a Submit button to capture the submit event. Under Microsoft® Internet Explorer 3.02, pressing the Enter key in a text field generates a submit event. In Internet Explorer 4.0, I can't get this event to fire on forms with more than one text field unless I add a Submit button. I've included a sample that works in Internet Explorer 3.02, but not in Internet Explorer 4.0 (see Figure 1).
GEEK Probably the easiest way to trap the Enter key and have it submit a form when one of the form's elements has the focus is to assign an onkeyup event handler for it. Here's an example:

 <form onkeyup="if (event.keyCode == 13) {ProcessForm()}" ...>
This will invoke the ProcessForm function any time the Enter key is pressed and released while one of the form elements has the focus.

GEEK I have designed an ActiveX control that can be used both within a LAN-based application and through Internet Explorer over the Web. I know I can use the codebase parameter of the <OBJECT> tag to automatically install the control from the Web, but I want to force users to do their first installation over the LAN because the installation package is too complex to run over a dial-up connection. How can I block users who haven't installed the control from accessing the Web page?
GEEK
There's the easy way and the hard way. The hard way is to go through the gyrations of creating a very lightweight ActiveX control loaded into an earlier page that determines if the user has the appropriate controls loaded on their system. The control could redirect the browser to some sort of warning about how the control needs to be loaded via the higher-speed LAN rather than the Internet connection.
      The easy way doesn't involve any of those gymnastics. On your Web pages, don't provide a codebase for the <OBJECT> tag that installs your ActiveX controls. That way, if the user hasn't installed the control yet (from the LAN), the control won't get created on the page. The computer won't be able to install the control since it doesn't know where it is.
      If you are using Internet Explorer 4.0 or later, then you can also easily provide the user with information on why they didn't see the control and how to remedy this situation:


 <object ...>
 <H2>Control Not Loaded</H2>
 Click <a href="instructions.html">here</a> to
 find out how to install this control.
 </object>
The only time the text within the <OBJECT> container will be rendered is when the object wasn't created for some reason. This provides you with a fairly straightforward way to assist the user in understanding why the control didn't run and the steps they must take to install it.

GEEK I've been trying to write a script to increase font size on an HTML page, but I can't seem to get it to work. My last try was this:


 Sub growBig
     Layer1.style.fontSize = Layer1.style.fontSize + 10
     myTimer =window.setTimeout("Call growBig",10)
         If Layer1.style.fontSize >= 100 Then
         Layer1.style.fontSize = 20
     end if
 end sub
 
 sub window_onLoad
     call growBig
 end sub
This was called with the following HTML snippet:

 <div id="Layer1" style="font-size:20pt">Hello there!</div>
GEEK There are two problems with your code. First and foremost, I have a problem with your method of growing the font on a timer. Expanding the font to a maximum size, snapping it back to the initial size, then repeatedly growing it again is extremely annoying. Growing the font size once and then stopping might be acceptable. Might.
      Second, the obj.style.fontSize property is a string value. In your particular situation it will look something like "20px." Clearly, trying to execute

 Layer1.style.fontSize = "20px" + 10
won't return anything valid. You need to somehow use a numeric representation of the font size instead of a string representation. The DHTML object model in Internet Explorer 4.0 provides some properties that are numeric representations of other styles normally exposed as strings (posLeft, posTop, posHeight, and posWidth), but it doesn't provide one for fontSize. This exercise is left for the geek.
      There are a number of ways to implement this. You could write a function that would strip apart the fontSize value and provide a numeric representation. One minor problem with this technique is that the tag with this style set

 <div style="font-size:larger">
will result in exactly what it says: Layer1.style.fontSize will be set to the string "larger," not a point size. I bet you'd have a hard time turning it into a numeric representation.
      An easier way to get around this problem is to simply add a custom property to your <DIV> tag, like this:

 <div style="font-size:20px" size=20>
Then change your code to

 Sub growBig
     Layer1.size = Layer1.size + 1
 
     If Layer1.size >= 100 Then
         Layer1.size = 20
     end if
 
     Layer1.style.fontSize = Layer1.size & "px"
     myTimer = window.setTimeout("Call growBig",10)
 end sub
 
which will use this size parameter as the number to be used in maintaining the numeric size of the font.
      As I mentioned earlier, this code is extremely annoying, so I recommend using this bare minimum procedure:

 Sub growBig
     Layer1.size = Layer1.size + 1
 
         If Layer1.size >= 100 Then
         Layer1.size = 20
     else
         myTimer = window.setTimeout("Call growBig",10)
     end if
 
     Layer1.style.fontSize = Layer1.size & "px"
 end sub
This will grow the font size once, then return it to its original size before stopping.

GEEK How can I automatically print several dynamically generated Web pages from my program? I tried using the Web-Browser object and either JScript® or VBScript, but I cannot print the contents of the WebBrowser object by itself. The OLE print command prints the entire visible browser page, including my embedded WebBrowser object.
GEEK The ExecWB method of the WebBrowser object should be fully capable of printing its contents as you describe. Assuming you have created a WebBrowser object named WB, then


 WB.Navigate "http://www.microsoft.com"
 ...
 WB.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPT
should produce a printout of the Microsoft home page.
      As for managing the printout of multiple pages, perhaps the best way to do this is for your ASP pages to realize that they are being asked to produce a printout, and to behave differently under that situation. They could actually generate one long page that includes all of the information that would normally be spread across several pages. You can utilize the CSS page-break-before style to assist with this:

 <style>
     .pagebreak {page-break-before: always}
 </style>
 
 ...
 
 <br class="pagebreak">
One way to do this would be to expose a special Print button. Clicking on this button would redirect navigation to the special printable version of the pages before printing them out. Depending on how you are providing your solution, you could even have the Print button load the page into an off-screen or hidden instance of a WebBrowser control and print from there. This would keep the user from being bothered by the browser window switching around.

From the October 1998 issue of Microsoft Interactive Developer.