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      Download the code (1KB)

GEEK I have Web pages that need to be printed in landscape format. Is there any way to code a Web page so that it will automatically print in landscape without making the user resort to print setup?
GEEK Nope—not yet, anyway. Automatic landscape printing is something that probably will be supported when browsers adopt Cascading Style Sheets level 2 (CSS2). When this happens, you'll be allowed to specify various printed page aspects of your Web pages such as orientation, crop marks, left or right-hand pages, and so on. For more information on CSS2, please check out http://www.w3c.org/TR/REC-CSS2/.

GEEK With ISAPI, how can I process the information in a Summary Information component (SumInfo)? I want to display a list of Microsoft® Word files with specific keywords.
GEEK The following ASP code should illustrate what you'd like to do:


 <%SumInfos.SetFileSpec strPath, strFileSpec%>
 <%if SumInfos.Count > 0 then %>
 <%For Each SumInfo In SumInfos%>
 <p>URL:  <%= SumInfo.URL%></p>
 <p>Title:  <%= SumInfo.Title%></p>
 <p>Subject:  <%= SumInfo.Subject%></p>
 <%end if%>
 <%next%> 
This code shows how to access individual elements of the summary information that are stored in a file. Figure 1 shows a list of properties available to the SumInfo component. For more information, see http://www.microsoft.com/windows/downloads/contents/ AdminTools/IISDocSummary/default.asp.

GEEK In your August 1998 column, you recommended the following line of code to set the focus of an Element:


 document.forms(index).elements(index).focus
This should work, but it doesn't. Without the parentheses after "focus", it won't work in JScript®.
GEEK You are correct. If you're using JScript the statement should read:

 document.forms(index).elements(index).focus();
However, I was using VBScript, not JScript. The original statement works perfectly fine in VBScript.

GEEK I want to set up a bracket chart for keeping track of tournaments using DHTML and tables, like the one shown in my Microsoft® Excel file (see Figure 2). When I choose Save as HTML in Microsoft Excel, I don't get the desired effect because HTML table cells don't have a border property, and I can't get a linedraw effect. Any suggestions?
Figure 2: Tournament Bracket Chart
Figure 2: Tournament Bracket Chart

GEEK The main issue to resolve when building a tournament chart is how to selectively specify top, left, bottom, and right border attributes. While this is possible using some rather fancy footwork with table cell background colors, it is fairly easy to achieve with Cascading Style Sheets. Figure 3 shows an example of using CSS to generate results like the page shown in Figure 4.
Figure 4: CSS Borders
Figure 4: CSS Borders
      CSS-based formatting like this is destined to be supported in future versions of programs that allow you to save files to HTML. But right now you must rely on other Web authoring tools to add this design feature. Disclaimer: Geek does not condone or support illegal wagering.

GEEK I have a Web page that opens Microsoft Word and displays a specific document. I've been using


 <a href="test.doc">OpenDoc</a> 
to do this. Although it works well, it seems to be very limited in functionality; you can't pass any kind of variables, such as merge fields, to the document. Is there any way to do this?
GEEK You are correct. The functionality available to Web pages to request an application to open up a document is extremely limited. This is by design because any further functionality would likely expose serious security problems, which would undoubtedly be quickly exploited by people with too much time on their hands.
      All you can do is continue to reference the document. You don't even have any control over which application will actually be launched when the user clicks on the link. It could be Microsoft Word, Lotus 1-2-3, WordPerfect, Notepad, or whatever application the user has specified to handle files with a .doc extension. You also can't control whether the application is launched separately or within the client area of the browser. This setting is also configured on a per-user basis on the client machine. And, of course, you have no way of querying the client system to discover how the user has their system set up.
      To gain the level of control you are trying to achieve, you would need to write an ActiveX® control, then code-sign it (through VeriSign or some other signing authority) so that users can be assured that the control is genuine.

GEEK When I press a button on my ASP-generated Web page, I want to refresh an ADO recordset and display a message box with the new record count. When I delete a record from the table from which I'm selecting rows and press the button, I'd expect one fewer row to pop up on the message box. But I still get the same number of rows. The only way to get the correct count is to refresh the page, then press the button again. Does ASP cache the recordset forever?
GEEK You seem to be having a common conceptual problem: differentiating between server-side script and client-side script. The fact is, never the twain shall meet—at least not the way you have it set up in your code. If your code looks like this


 <SCRIPT LANGUAGE="VBSCRIPT">
 <!--
 Sub cmdRefresh_Click()
     MsgBox <%=lngCnt%>
 <%
 ' here you have server side code to whack on the database
 ' and delete a record, and then count the records, and
 ' store the value in "intCnt"
 %>
     MsgBox <%=intCnt%>
 End Sub
 -->
 </SCRIPT>
then anything you have in the ASP file within <%...%> will be executed before the page is sent down the pipe to the client. This code will not be executed again when you click on the input button on your page. If you try doing a View Source on this page in your browser, you'll see something like this:

 <SCRIPT LANGUAGE="VBSCRIPT">
 <!--
 Sub cmdRefresh_Click()
     MsgBox 234
 
     MsgBox 234
 End Sub
 -->
 </SCRIPT>
GEEK Is there an update of the browscap.ini file that supports Microsoft Internet Explorer 4.01 and higher? Is there a better way to capture user information than the following:

 <%  Set bc = Server.CreateObject("MSWC.BrowserType") %> 
GEEK You can obtain updates to browscap.ini at http://www.cyscape.com/asp/browscap. While there, you'll also see that Cyscape has developed a browser sniffer object called Browser Hawk. You might want to take a look at it at http://www.cyscape.com/browserhawk/compare.asp.

GEEK I have a SQL Server™ database in which I store images of my products. How can I read this database using ADO and display the returned images in HTML?
GEEK It all depends on how you are storing the images in the database. If you are storing the raw binary data of a GIF or JPEG image, you're in luck. Images are properly stored in the database as Binary Large Object (BLOB) fields. To retrieve the data with ADO, you can use the GetChunk method of the Field object. Here is a fragment of sample code from Microsoft Internet Information Server Resource Kit (Microsoft Press, 1998) that illustrates this.


 fld = rs("ImageData");
 cBytes = fld.ActualSize;
 Response.ContentType = "image/jpeg";
 Response.BinaryWrite (fld.GetChunk(cBytes));
GEEK Is there any way for a local executable to set cookies that map to a Web site's domain and path? I am interested in doing this for both Internet Explorer and Netscape.
GEEK You want to write an executable that spoofs a Web site's domain and path in order to open up a cookie and read it? That sure sounds like something you should be prevented from doing.

GEEK In a Web page, how can I test whether a user has an ActiveX component installed on the remote machine? The only solution I've found is to use the following syntax:


 Dim xxxyyyzzz
 Set xxxyyyzzz = CreateObject("NameOfTheObject") 
If an error is returned, this means that the control is not installed. And this sample doesn't work under Internet Explorer 3.x anyway, because VBScript 1.x doesn't implement the CreateObject function.
GEEK Unfortunately, the only solution I can offer is to write an ActiveX control that sniffs out other ActiveX controls. Since it would be an extremely lightweight control, it wouldn't take long to download and install.

GEEK Does VBScript have a setTimeout similar to the function in JScript?
GEEK Yes. But technically it is not VBScript that has the setTimeout function, but the window object that exposes both the setTimeout and setInterval methods. These can be called from either VBScript or JScript. You can get further information about setTimeout and the other methods available from the Internet Explorer 4.0 and 5.0 object models at http://msdn.microsoft.com/workshop/ author/dhtml/reference/methods.htm.

GEEK In several of my ASP pages, I write lines of HTML to the browser while a credit card is being processed so the customer can see the transaction's progress. These new lines are written at the bottom of the page, and since they are appended to the existing material on the page, the user has to scroll down to see this new information. Is there some way that I can automatically scroll the browser as new lines are appended to the bottom of the screen?
GEEK The Document Object Model (DOM) that was introduced in Internet Explorer 4.0 includes support for a method called scrollIntoView, which is exposed by most of the HTML elements in the DOM. For Internet Explorer 4.0, you can simply invoke that method and the item referenced will scroll into view.
      A lower-tech approach would be to use named anchor points within your document to force scrolling to a particular position. For example, your extruded page code might look something like


 <a name="Step1">Step 1.</a>
 ...put your information here...
 <script>location.href="#Step1"</script> 
which should cause the page to scroll, revealing the new information as it is exposed. If you are displaying a lot of information, you might even want to place the named anchor at the bottom of the status information.
      If cross-browser compatibility is really important to you, I recommend rethinking the solution you are trying to provide to the user. The above process should work on most browsers, but it is not only relying on the browser for scripting support, it is also dependent upon how a browser dynamically scrolls to named anchor points. It's possible that older versions of either Internet Explorer or Navigator might behave slightly differently.
      Perhaps the most straightforward approach would be to simply have the status page display nothing but status update messages, allowing more room for the data to be appended. Once the process is complete, you would navigate to a completion page.
      Another approach would be to use server-side browser sniffing, allowing you to adopt a high-tech approach to better use the functionality of the latest versions of Internet Explorer and Navigator, but switch back to a less ambitious version of your page for older versions of the browsers. If you want to go this route, I'd recommend going as high-tech as possible.
      Instead of simply using a scrolling page of status messages, you can actually provide a dynamic display of status messages. Using DHTML, you could easily display a progress bar to indicate to the user just how far along in the process they are, and combine it with a dynamically updated message about what is going on at that moment. Since your server-side code could track how long each step was taking, and measure that against previous benchmarking, you could even show the user a relatively accurate estimate of how much longer they might have to wait. Depending on how long the process might actually take, you could also help the user pass the time with additional information messages, or even (shudder) scroll through some advertising banners while you've got the user by the eyeballs, expectantly waiting for this process to complete.

GEEK Could you refer me to some good sites with information on Web design interface?
GEEK Web design is steadily evolving. There are hundreds of Web sites that attempt to provide information for budding Web designers about the right and wrong ways to put together effective Web sites. Many Web sites contradict one another, simply proving that this is a realm where individual creativity is the primary rule.
      Here are a few places that I can recommend:
       http://msdn.microsoft.com/workshop/Design/ This is where the Microsoft Site Builder folks provide some information and guidelines on possible approaches to Web design. You'll find articles on color management, typography, design and layout. I've even authored a few of these articles myself.
       http://www.Lynda.com Lynda Weinman has written several wonderful books about Web design, specifically targeted at graphics and their proper construction and use. You can find design tips, links to additional design sites, as well as information about her excellent books here.
       http://www.KillerSites.com This is the Web site for David Siegel's book, Creating Killer Web Sites (Hayden Books, 1997). I highly recommend spending time with both the Web site and the book. While you might often run into people who attempt to dismiss David's opinions and design ideas, I feel these people are simply jealous of his creativity. Keep in mind that what he is presenting are his opinions on Web design, and you'll be able to learn a lot.
       http://www.WebPagesThatSuck.com Probably the best way to see what works and why is to look at what doesn't work. This is an insightful, creative, and often humorous site that showcases many of the horrible practices that some people actually thought were good design. Pretty scary stuff.

From the November 1998 issue of Microsoft Interactive Developer.