Jeff Brown
Rafael M. Muņoz
Microsoft Corporation
August 4, 1997
Updated: December 15, 1998
The following article was originally published in the Site Builder Magazine (now known as MSDN Online Voices) "Web Men Talking" column.
Contents
Try again - Custom messages from Web servers
Activate me - Activating buttons on a navigation bar
Puzzle pieces - ActiveX and JavaBeans
Revelation experience - One background image for all screen resolutions
ActiveQuestions - ActiveX controls and ActiveX server components
Protecting the cookie jar - Java applet and cookies
Ah, the dog days of summer. Take your laptop out to the porch. Pour a glass of lemonade (but not onto the computer). The Web Men are happy and relaxed after their break -- and ready to tackle questions ranging from JavaBeans to background images. Settle into the heat, slow down, and read on:
Dear Web Men:
Hey, you know how you may go to a site, but type in a page wrong and instead of getting the HTTP/1.0 404 Object Not Found error, you get forwarded to a page that says that the URL you typed doesn't exist on this server? An example of this would be at www.pcworld.com. If you type in a page that doesn't exist on pcworld.com you go to a page that has links on it and other things. How are they able to take pages that don't exist on their server and forward them to a page to handle it? I would greatly appreciate it if your eternal flame of knowledge can shed some light on this subject for me.
Lee Westenberger
The Web Men reply:
Hey Lee, sometimes we think our "eternal flame of knowledge" is more on the scale of a bright birthday candle, but we'll see what we can do here.
What you're describing is actually a feature supported by the Web server hosting the site. Some Web server software enables you to return a custom page to users for errors or other status information, rather than forcing the browser to display the ugly (and uninformative) HTTP status text. One example of such a server is HTTPd, developed by the National Center for Supercomputing Applications (NCSA). There are other Web servers that support this, too.
Current versions of Microsoft Internet Information Server (IIS) do not directly support this feature. But if you were using IIS, you could develop an ISAPI filter to provide custom messages to the user, or do any other custom processing you wanted.
The next version of IIS will support custom error messages and a ton of other new features. Beta 2 of IIS 4.0 is available for download now. Go give it a test drive.
Dear Web Men:
Great Column - very useful!
Question: I am trying to use the OnMouseOver command in JavaScript to swap images in the navigational bar on our Web site. Thus, a "non-active" button can go to an "active" button when the user moves the arrow on top of the button. I can get this to work in the browser that starts with an "N," but your browser does not support the same script. I seem to have problems with the image() object. Anyway, can you recommend a script that will perform the above action in Internet Explorer 3.02? (I know it will work in 4.0, but none of our users currently use 4.0!)
I know a lot of people beside myself who would like to know how to do this, so it might be an interesting section in your column.
Thanks for the help!
Josh Bryant
The Web Men reply:
Interesting section in our column? You're right, Josh! This has been asked a couple of times, so we set out to come up with some ways to do it. As you pointed out, the browser that starts with an "E," unfortunately, does not support the image() object. You are also right about Internet Explorer 4.0 supporting this -- and as you will see in our sample below, we have taken this one step further and demonstrated how it will also work with Dynamic HTML.
Because we can't use the image() object in Internet Explorer 3.02, we've had to come up with a couple of other ways to perform the MouseOver effects. Now, the ways that we came up with will require a little bit of browser detecting, but the effects in both browsers are definitely worth the check.
Before we describe our solutions, let us answer the question that some of you are now asking -- "How do I detect the browser type?" For information on this, check out the previous Web Men Talking answers: "Don't I know you?" for an Active Server Page solution, and "Which side are you on?" for a JavaScript solution.
We came up with two solutions that will work with Internet Explorer 3.02 , plus the one that uses Dynamic HTML in Internet Explorer 4.0. Our first solution features the HTML Layout Control: We use the hotspot control and swap images as the mouse moves over them. In our second solution, we take advantage of the MSDN Online Navigation Bar, an ActiveX control that has already been created for us by our loving folks at the MSDN Online.
Last, but not least, we use the power of Dynamic HTML to create, in our opinion, a definitely slicker solution. It takes fewer lines than the other two and is overall less work. Remember, this example can only be viewed with Internet Explorer 4.0 . We figured you already knew this, but for the benefit of our other readers we have included the code so they can see just how easy it can be.
Dear Web Men:
Could you please explain to me what ActiveX and JavaBeans are, and how they can be applied to my Web pages?
Peter Winter
The Web Men reply:
Sure. ActiveX and JavaBeans are just two pieces of technology that can be snapped into the Web site building puzzle. (Nice analogy, eh?)
ActiveX is a set of extensible technologies that can be combined together to build highly interactive software. Remember that ActiveX, in general, is much broader than JavaBeans.
An ActiveX control is typically what someone incorporates into her Web page. (The use of scripting on a page in Internet Explorer brings into play another ActiveX technology: Active Scripting.) You include an ActiveX control on your Web page using the <OBJECT> HTML tag. There are tools to do this visually, such as the ActiveX Control Pad, Visual InterDev , and many others, and they make using controls a no-brainer. For the complete story on ActiveX controls, peruse the ActiveX controls overview in the MSDN Online Web Workshop.
A JavaBean is similar to an ActiveX control in that it is a reusable component that can be used on multiple Web pages, and in stand-alone applications. Both ActiveX controls and JavaBeans have properties, events, and methods. Properties affect the appearance, or state, of the control or bean (for example, the font it uses). Events are notifications sent by the controls or beans to let programs using them know that a specific action has occurred, such as a mouse click or mouseover. Methods are other functions that can be called to control the control (or bean). Whew!
To incorporate a bean into your Java applet or application, you can use what is called a builder tool. For more details on JavaBeans, check out some of the JavaBeans resources listed at Gamelan Java Directory.
A big difference between ActiveX controls and JavaBeans is that a control can be developed in any programming language, but a bean must be developed in Java. Also, ActiveX controls run only on the Windows and Macintosh platforms, but a bean can be used on any platform that supports a Java Virtual Machine and the JDK (Java Development Kit) 1.1.
Controls and beans can also be used together and interoperate through bridges. Controls can be exposed as beans and vice versa. This functionality is available in the Microsoft SDK for Java 2.0 .
Dear Web Men:
Hello, Web men!
I want visitors to my site to have a particular kind of experience. To begin with, I want them to see my entire background image picture, no matter what their screen extent: 640x480, 800x600, or even 1024x768. If Explorer 4.0 won't scale one background picture to full-screen, I'd be happy to prepare a different picture for each screen size. Well, I wouldn't be happy, but I'd do it. Is there a more elegant solution? If there were, I'd be happy to hear about it.
George D. Girton
The Web Men reply:
George, you must have some pretty wild images that you want to share full-screen! Remember that pretty is as pretty does, and don't get too wild and crazy on us. We are still trying to understand half of what we saw in the Louvre during our vacation.
We figure that you are already well aware of the fact that any background will always cover the entire screen in a browser window, because it takes on a tiled effect. Patterns work great in this case.
Here are a few items that we should point out:
With all this said, don't get the feeling that we are trying to talk you out of anything. We think the experience you could provide the Web surfer might be pretty cool. You mentioned the use of Internet Explorer 4.0 . The Preview 2 version, with the new technologies it offers, would be ideal for this situation.
Two ideas come to mind that. The first is to use Dynamic HTML (DHTML) and a simple image. With DHTML and the STYLE attribute, you can have control over the absolute position and z-order of the image in the <IMG> tag. A simple statement, such as
<img id=bkgrnd src="myspecial.gif" style="position:absolute;left:0;right:0;z-index:-1">
placed after your <BODY> tag will cause myspecial.GIF to be positioned at the top left corner of your page, and will push the z-order down. Then in the OnLoad event, and with the help of the SCREEN object, we can obtain the screen resolution through the WIDTH and HEIGHT attributes, and can set the IMG object's own WIDTH and HEIGHT, accordingly. This sizes an image to the desired size and places it in the background of our page, so that text can be displayed on top of it.
Another solution would be to create a vector graphic by using the Structured Graphics Control, one of the many new DirectX Animation Controls now available with Internet Explorer 4.0. This graphic would be lightweight; fully capable of being scaled (good for us!), or rotated in three dimensions (added bonus!); and could be filled with solid, pattern, or gradient fills. We would basically handle this control similar to how we handled the image above, having total control through the use of Dynamic HTML.
Wow, that's a lot to digest. To help you through it, we highly suggest checking out the Direct Animation SDK Documentation , which contains more information on the Structured Graphics Control. Also, cruise through the DHTML, HTML & CSS area for detailed information on Dynamic HTML and the object model associated with it.
Hey, George: Before we go, be sure to get back to us with information on what you do. We would love to see what cool experience you end up creating!
Dear Web Men:
I know that an ActiveX control can be included in ASP.
I know that ASP also includes many ActiveX server components, such as DB-Access component and AdRotator component.
What I want to know is:
1. In ASP, can an ActiveX control be displayed in all Browsers (i.e., Netscape without a plug-in)?
2. What is the difference between ActiveX control and ActiveX server
component?
Dennis Chen
The Web Men reply:
Good questions, Dennis! Typically, an Active Server Pages (ASP) script outputs an HTML page. To answer your first question: You could put in an <OBJECT> tag to include an ActiveX control on the page, but in order to see the control, the browser receiving the page would still have to support ActiveX controls. So, no. Using ASP does not magically enable all browsers to display ActiveX controls. It does enable you to detect when a browser does not support ActiveX, and send content that browser does support.
The answer to your second question is a tad more complex. The difference between ActiveX controls and ActiveX server components is the specific Component Object Model (COM) interfaces they support and use. Conceptually, they are the same thing -- COM-based components with some prepackaged functionality. But there are many specific differences. A server component has no need for a user interface (UI), so there is no need for a server component to support COM interfaces dealing with UI, but a typical ActiveX control used on a Web page does. An ActiveX control does not necessarily support automation, but this is required for a server component. An ActiveX server component must be an automation server. It is quite possible that a given component could be used both as an ActiveX control on the client, and as a server component on the server with ASP. But the component must support the COM interfaces required for both.
For all the specifics on developing an ActiveX server component, refer to the Programmers Reference in the Active Server Pages Roadmap documentation. To get the facts on developing other ActiveX components, including controls, check out the Web Workshop's Component Development section.
Dear Web Men:
I sure hope you can help me with this little problem I'm having. The problem is with finding information on implementing cookie functionality into my Java applet. How can I write to and read from a cookie from within my Java class? Thanks for pointing me in the right direction!
Brian Buff
The Web Men reply:
Well, Brian, this is a touchy one! We are pushing the security boundaries here for a Java applet. You are not testing some weird security bug are you? We don't want any kind of cookie monster applet running around the Web eating up cookies.
Security features of a Java applet state that by itself, an applet cannot access resources outside the Java sandbox. Now, this is for security reasons on the Internet. A standalone applet can access resources, but then it's running outside of the sandbox and the browser -- and directly on your machine. You can, however, create what is considered to be a trusted class, which will allow your applet access to resources outside the Java sandbox. This is where Cabinet files, or more commonly referred to as CAB files, and the Authenticode technology come into play.
CAB files are specially compressed files that can be used to package an applet together for download on the Internet. One great thing about CAB files is that they can even cut down on the download time of your applet. When you incorporate code signing, such as Authenticode, you can create a sense of security for users downloading your applet. Once downloaded, the CAB file contents are extracted and installed on the user's machine. You can think of this in the same fashion as what you see happening now when downloading an ActiveX control.
There is a ton of information on CAB files. We suggest checking out the Microsoft Knowledge Base articles, INFO: Frequently Asked Questions for CAB Files and INFO: Frequently Ask Questions About the SDK for Java . Also check the Visual J++ Product Support Page for more information. And you can find information on new code signing tools by following the Tools link on the new Microsoft SDK for Java .
Good luck, and remember to stay security savvy. Should you ever have any security question, you can always find security information at the Microsoft Security Advisor site.
Jeff Brown, when not forcing family and friends to listen to Zydeco and country blues music, provides technical support for the Microsoft MSDN Online with a smile.
Rafael M. Muñoz (the even bigger smile above) is a part-time Adonis, and full-time support engineer for Microsoft Technical Support. He takes it very, very personally every time you flame Microsoft.