ASK THE WEB MEN
Send your Web development questions to the Web Men at webmen@microsoft.com.
 

by Rafael M. Muñoz & Tom Moran

New Look, New Site, New Web Man

March 30, 1999

That's Tom Moran, your new Web Man, talking. Formerly of "Servin' It Up" fame, Tom has joined Rafael to answer your Web development questions -- and on this spanky new site, to boot.

For their inaugural column in MSDN Online Voices, Tom and Rafael tackle such topics as dynamically sizing objects, Java classes, pop-up menus, and the dreaded spam. All that -- and a raft of shorts (quick answers to quick questions).

Get your coffee, sit up, read up, and say hello to Tom.

Contents
A size for all occasions - Dynamically sizing objects in Internet Explorer
Pass me the spam, please - Collecting and validating e-mail names
Caffeine fix - Troubleshooting problems when downloading Java Classes
Poppin' fresh - Creating popup menus
The Web Men in short

A size for all occasions

Dear Web Men:

How do I use JScript™ variables as HTML attributes?

What I want to do is get the width and height of the browser window, and then use that information to size an object (a map) on the Web page. I can get the width and height just fine, but I'm having trouble getting that data into HTML WIDTH and HEIGHT attributes.

I have it figured out on the Navigator side. JavaScript allows the use of special character entities in attributes. For example, my script gets the width of the browser window and subtracts to account for other elements on the page and places it in the variable mapWidth. In Netscape, my HTML looks like this:

   <OBJECT ID=... WIDTH=&{mapWidth}; ...>
      ...
   </OBJECT>

This HTML doesn't seem to work in Internet Explorer. Is there an equivalent mechanism in Internet Explorer?

Thanks!

Dave Delage

The Web Men reply:

Dave, it looks like you found a Netscape JavaScript entity, but in Internet Explorer Non-MSDN Online link, I guess we would call it a non-entity - since, as you pointed out, it's not supported. An entity is one of the many ways Netscape and Microsoft go above and beyond the current ECMAScript standards, ECMA-262 Non-MS link.

But don't worry, we won't leave you high and dry. With a combination of JScript Non-MSDN Online link and Dynamic HTML, we'll get you the effects you want with Internet Explorer Non-MSDN Online link. If you really feel adventurous, Internet Explorer 5.0 Non-MSDN Online link provides a new way of achieving the same effects: dynamic properties. Let us point out that dynamic properties are only available with Internet Explorer 5, and that unfortunately, neither dynamic properties nor our solution below will work with Netscape. So you will need to do a little browser sniffing before you load your page. For some great information on browser sniffing, see Sniffing For Browsers, Java Virtual Machines, and Operating Systems.

Our script snippet is pretty straight forward. We create a function called window_resize() in which we use the <BODY> element of the document object to obtain the clientHeight and clientWidth properties. We then scale these two values as we see fit, and use the results to set the HEIGHT and WIDTH attributes of our object, which we call object1, using the <STYLE> element.

After the function is defined, the onload and onresize events of our window object are set to call our resize function.

   function window_resize()
   {
      object1.style.height = document.body.clientHeight * .75
      object1.style.width = document.body.clientWidth * .75
      window.status = document.body.clientHeight
   }
   window.onload = window_resize
   window.onresize = window_resize

We don't even have to add the width and height attributes to the <OBJECT> tag, as you show above; all we need is an ID, and the rest is done dynamically. There you have it. Enjoy.

TopBack to top

Pass me the spam, please

Dear Web Men:

How do I automatically capture and then validate an e-mail address from a user of my Web site?

Vince Mundo

The Web Men reply:

Hey, good idea -- every person who viewed this answer could get a nice follow up e-mail and advertisement. You wouldn't mind, would you?

If you are on the Internet, you really don't have much of a choice: You have to ask a user for her e-mail address. Then it becomes a matter of validation; we know it's rare on the Internet, but people do lie occasionally. There are two forms of validation you need to worry about:

There are several ways to validate an e-mail address after collecting it. The lowest-level validation is to check for a "@" somewhere in the string, although it should be obvious that this isn't perfect. You would simply use something, such as the instr() function, to check for the presence of "@" in the variable that holds the user's e-mail name.

You can get quite complex in the algorithm to check for a valid e-mail address, because there are many different ways to structure an address, and it isn't always '[name]@[domain]'. One component we've seen (but haven't tried) is from Software Artisans and is called SA-CheckNon-MS link. If you really want to get fancy and do it all yourself, pick up the book Mastering Regular Expressions Non-MS link from O'Reilly. Both Visual Basic® Scripting Edition (VBScript) and JScript® support regular expressions now.

The next form of validation is to ensure that the address is real -- and that a real person is at the other end. To do this, you need to send a piece of e-mail to the address you've collected, with some sort of token, such as a password or special number. If it doesn't bounce and you get a reply back, you can be pretty sure that it is a valid address with a person answering. Many listservers and public discussion forums work this way. To send mail from an ASP page is easy, and the following code from a previous WebMen column shows you just how easy:

<%@ LANGUAGE="VBSCRIPT"%>
<%
Dim myMail
Set myMail = CreateObject("CDONTS.NewMail")
    myMail.Send Request.Form("From"),
    Request.Form("To"),
    Request.Form("Subject"),
    Request.Form("message")
Set myMail = Nothing
%>

Retrieving and validating the e-mail is more difficult, and is left as an exercise for you. An ASPMail component isavailable from ServerObjects Inc. Non-MS link, which can possibly make things easier for you, depending on your situation.

Now let's assume for a minute that you are not on the Internet, but rather on an intranet. You have a nice, cozy, secure environment, and you know your customers are all using Internet Explorer. Sunddenly, it gets easy to pick up the e-mail address. You simply enable NTLM authentication for your site, which can be configured through Internet Information Server (IIS). Since using NTLM forces a logon authentication, you will have access to the user's account information, and you can pull it out easily using the Request object. The following line of code will grab the user's logon name, which is generally also that user's e-mail name:

<%
strNameIncludesDomain = Request.ServerVariables("LOGON_USER")
%>

Note that the logon_user server variable includes the domain name, soyou'll see something like MyDomain/UserName. You'll need to strip off the domain name at the beginning and then you are left with the user's actual logon name. The Request.ServerVariables documentation is available in your Windows NT Option Pack Non-MSDN Online link documentation.

If you want to find out more about varying types of authentication -- and how that differs from validation, encryption, and other security concepts -- see The Basics of Security and Authentication and Security for Internet Developers (older but still good).

Hopefully that helps answer your question, and you don't get into too much trouble.

TopBack to top

Caffeine fix

Dear Web Men:

I'm trying to download a set of Java library files for use with Internet Explorer 4.0. I've tried using cabarc and a .inf file, and also have tried using dubuild. I've been successful in getting the Java classes to download and install, but Internet Explorer can't find them. The instructions for dubuild look so simple that it's hard to see what I could be doing wrong. My test HTML applet tag looks almost identical to the one given in the dubuild instructions in the SDK for Java 3.1. The only difference is the names of the directories and packages. Could you point me to something or someone that may be able to help? The Netscape Java library download and install process, though complicated, at least works.

Tim Haywood

The Web Men reply:

Tim, you're making things a little tough on us -- but we are familiar with Java (or was that the caffeine effects of java due to those late night staying up preparing our column?). The hard part here is that we don't have any specific errors or description of what exactly is happening.

Microsoft Support handles these types of questions every day. We'll approach it the same way: We'll run through some generic checks, and point you to some great references in this area; hopefully you'll find something that helps. In fact, this is one of the popular topics with the Java Support team.

One thing to check always is that you have the latest Microsoft Virtual Machine for Internet Explorer. This will ensure that you aren't running into any existing problems with old Virtual Machines. Another great place for specific information is the Java Console window. See question 1.04 of the Microsoft Knowledge Base article Q169173, INFO: Frequently Asked Questions for Visual J++ Non-MSDN Online link, on how to set this up in Internet Explorer Non-MSDN Online link. Errors found in the console window can then be searched for at the Microsoft Product Support Services Non-MSDN Online link site, or you can discuss them with a Developer Tools Support Engineer; they will definitely provide more details to the person who answers your phone call.

You can also start with a generic sample -- one that is known to work. It can assist you in finding small details you might have over looked when working with your project. You'll find three great samples in the Microsoft Knowledge Base article Q193877, HOWTO: Make Your Java Code Trusted in Internet Explorer Non-MSDN Online link. The article walks you through, step by step, the creation of a generic sample with both the Cabinet File Archiving Utility, cabarc, and the Distribution Unit Archiving Utility, dubuild; see the Microsoft SDK for Java documentation for more information on these utilities. The article also has some good references to other articles that can assist you in your troubleshooting venture.

TopBack to top

Poppin' fresh

Dear Web Men Talking,

I am very intrigued by Microsoft's Pop-Up Menu Bars at the top of almost every page Microsoft has on their Web site.The ease of navigation when you use mouseover effects to navigate to each subject matter is something I could really use (also displayed on MSNBC.com's page on the left-hand side) for a page I'm constructing.Is there any DHTML or JavaScript I can use to do this type of navigation?

Please Help!!

Thank you!

Brandon

The Web Men reply:

We're happy to help. In fact, we get this question at least one or two times a week, so you're not alone. Once you know how, it really isn't very difficult at all. We'll tell you the concepts involved, and then point you to some existing articles that cover this; there are at least as many different ways to implement these effects as there are programmers. The articles can just be a bit difficult to find.

There are really only three key concepts, and you should try to review them before you start to read any of the articles. They are:

You still have to worry about cross-browser functionality, down-level versions of Internet Explorer, proper positioning, and so on. To dive into implementation, you'll want to see the following articles and sites. The first one is one of the best and most recent; it not only provides details of how the former Site Builder Network site's pop-up menus were created, but gives working code as well.

Note that these solutions generally don't work with Netscape browsers. For some great cross-browser samples, go to the DHTML Lab Non-MS link.

TopBack to top

The Web Men in Short

Q: Julian Wraith and Allan wants to know how to publish an Access database to a Windows NT server.

A: Refer to the Microsoft Access Internet Non-MSDN Online link site.

Q: Jaslyn wants to provide tooltips for individual items in a list box or drop-down list.

A: The OPTION element does not fire an onmouseover event, so there is no way to determine which item you are over.

Q: Ric M. Macaraeg wants to e-mail information received from a form to a specific address.

A: See the archived Web Men Talking answer ER.

Q: Reinhard Piper wants to display a list of files contained in a directory.

A: Refer to Spilling the contents.

Q: Deborah Rhoads wants to build a search engine.

A: Refer to Microsoft Windows NT Server Web Services/isapi/gomscom.asp?TARGET=/ntserver/web/default.asp for complete information on Microsoft Index Server.

Q: Philip Quinn wants to know what is meant by adding a "?something=somevalue" to the end of an ASP file URL.

A: The "?" appends a query string to the end of the URL, which can then be retrieved by the QueryString collection and used by the script found on the ASP file.

Q: Keif Mayers wants to target a previously opened window with user-chosen content.

A: Ensure that a name is used with the open method of the window object, then use the TARGET attribute of the <A> element. Refer to the QueryString collection to pass the users selection to the target window.

Q: William Schwartz wants documentation on the Windows Media Player.

A: The Microsoft DirectX Media SDK site contains developer's documentation on the Windows Media Player Control.

TopBack to top

 


Rafael M. Muñoz, when not playing or coaching his favorite pastime (volleyball), provides technical assistance as a full-time developer support engineer for Microsoft Technical Support.

Thomas Moran, when not struggling to maintain some semblance of sanity (working with Rafael certainly doesn't help), toils with a prodigious team that creates articles and other content from Microsoft's Developer Support.


Archived Web Men Talking columns

1999
June 7    Forms and Functions
May 3    A Contest of Sorts
March 30    New Look, New Site, New Web Man
February 1    All of the Above
January 4 To '99 and Beyond
1998
December 7 See It, Hear It, Publish It, and Put It Somewhere
November 4 No Problem Too Small, No Screen Too Big
October 5 How Do I Look?
September 8 Something Old, Something New: Visual Basic and XML
August 3 Java, Pictures, and Positioning -- It's All Relative
July 6 Here, There, and Virtually Anywhere
June 1 Channel Your Efforts
May 4 Peace, Love, and Understanding ActiveX Controls
March 2 All Answers, All the Time
February 2 No Server to Call Your Own
January 5 In With the New
1997
December 1 New Life and Missing Links
November 4 <TARGET="Gobble_Gobble">
October 6 Autumnal Husbandry: Reusing Script Files, Automatic File Lists, and Other Thrifts
September 8 The Long and the Short of It
August 4 Beans, Cabinets, Cookies, and a Revelation
July 7 Standing Out in the Crowd
June 23 Bill the Bard, Roses, and Getting Around
June 9 Who Is It, Where Is It, and Why Won't It Fit?
May 27 Cookies with Your Coffee
May 12 Framed! The Web Men's Shocking Story
April 25 Express from our Riders of the Cyber Sage
March 27 Some Code to Go with that Java?
February 27 Talk to a Real, Live Web Man


Photo Credit: Katie McCullough/Katie McCullough Photography



Back to topBack to top

Did you find this article useful? Gripes? Compliments? Suggestions for other articles? Write us!

© 1999 Microsoft Corporation. All rights reserved. Terms of use.