Share via


Image Map Tooltips, Mouseover Effects, Script Execution Order, XML Schemas, and More
Edited by Nancy Michell
Q I need to create an image with different hot spots that will display text when you hover the mouse over it, like an infotip does, but I don't want to use hyperlinks. An example would be a map of the states that would display information about each state when you put the cursor over it.

A You could use a regular client-side image map and put an onmouseover event in the image map <AREA> like so:
  <MAP NAME="map1">
<AREA="1,10,50,200" onmouseover="jsfunction();">
</MAP>
••• 
<script language=javascript>
function jsfunction()
{
    alert("here");
}
</script>

      It works great in Microsoft® Internet Explorer, but remember this won't work in Netscape 5.0 and below.

Q I'm using JScript® for a popup menu in which I'd like to change the text to bold and a different color on the mouseover event. Do you have any suggestions, or even a pointer to a good code library?

A The most efficient way to enable a mouseover effect in Internet Explorer is to define the look you want through Cascading Style Sheets (CSS), then modify an element's current style sheet in response to an onmouseover event. For instance, if you define a style sheet like this in your document:
  <STYLE>
BODY { background-color: black;color: gold;font: 24pt sans-serif; }
UL.ActivateTextEffect { color: orange;letter-spacing: 2;}
</STYLE>

      You can change the className attribute of an element on mouseover with a couple of attributes:
  <BODY>
<UL onmouseover = "this.className ='ActivateTextEffect'"
  onmouseout = "this.className =';'">Mouse over me!
</UL>
</BODY>

      You can test this yourself by creating an HTML document that contains the previous nine lines.
      You'll find more information on this mouseover effect in the article titled "How to Manipulate Text Effects in Response to Mouse Events". MSDN Online also hosts a catalog of Internet Explorer samples that may be useful to you. See https://msdn.microsoft.com/workshop/samples/all.asp.

Q In the following HTML page, will First.js always be loaded before Second.js? Will it be a problem if Second.js needs to access a variable defined in First.js?
  <html>
<script language="JavaScript" src="/First.js"></script>
<script language="JavaScript" src="/Second.js"></script>
</html>

A The loading of the scripts is asynchronous, but if you use the readyState property of the script, you can find out if a script has finished loading before using it. The readyState can take the values shown in Figure 1. When a script is finally finished loading, its readystate would be "complete". Since you don't want to keep polling the script's loaded state, you'd want to find out the state using the onreadystatechange event. This performs the check asynchronously. This event will be thrown when the readyState of an object (such as a script) changes. However, you have to tell the object (script, in your case) that you want to receive changes to its readyStateâ€"you do this by writing code like that in Figure 2. You can read about the readyState property at https://msdn.microsoft.com/workshop/author/dhtml/reference/properties/readystate_1.asp. Please note that this solution (using readyState) is only applicable to Internet Explorer, not Netscape and other browsers.

Q When defining an XML schema you can use a partial schema defined elsewhere and effectively import the definition via a namespace. However, you still seem to need to repeat the definition in the outer schema, otherwise validation fails.
      As you can see in Figure 3, Address is defined in one file. Person, defined in another file, refers to the Address as the Home element (see Figure 4). This schema is invalid.
      However if you refer to the Address but completely include the definition (prefixed with namespace) it is valid. Am I missing something or is the use of namespaces just not fully implemented yet?
      Also, is there any way to define an ElementType using an existing type from a namespace, like this:
  <ElementType name="Home" add:type="Address"/>

      Here, Home would be a type of Address. So you could then have Home, Work, and so on, all with the same element definitions but using different names. Can this be done?

A This is a problem many readers have faced. First, your difficulty stems from the common misconception that referencing a definition in another schema will import that definition into the current schema. A reference is just a reference. Just as a design spec might say, "parameter A is a float as defined in Internet Explorer," a schema can say "allow the use of element foo, as defined in this other schema over there." In the first example, you would not say that the design spec defined what a float was, rather that it referenced an existing definition.
      What you are looking for in this import mechanism and in your question about defining an ElementType is the ability to subtype, and this is not supported in XDR (XML-Data). It's supported in the W3C's schema language, but that spec isn't finalized yet.

Q I'm attempting to use XML and XSL on a Web site I'm developing. I want to grab a page from a different server. The page is an ASP page, but it writes an XML output stream. I would like to get this XML, then use XSLT to format it and place it on an ASP page. I have been able to do this with local XML and XSL (see Figure 5). How can I do this with the XML coming from a different server?

A MSXML 3.0, which you appear to be using, has added support for server-side HTTP requests. Immediately after you set the async property, add the following code:
  xmlDoc.setProperty("ServerHTTPRequest", true)
xmlDoc.load https://YourURL
      If you're trying to access a URL from outside your proxy, you'll also need to run the WinHTTP proxy configuration utility. See https://support.microsoft.com/default.aspx?scid=kb;EN-US;q281142 for details.

Q I'm trying to write out the contents of the Temporary Internet Files folder into a text file and open that file in Notepad. It works fine with the Temp folder, C:\, and some other folders I've tried. When I point it at the Internet Explorer Temp folder, I only see desktop.ini with a count of 1 listed. When I look at the actual folder via Windows® Explorer there are 52 files in it and desktop.ini isn't one of them.

A This can be a confusing issue. The Temporary Internet Files folder is a view on quite a few different folders, not just a single folder itself. When you view the folder in Explorer, you get an Explorer extension that knows how to understand the cache and provides you with a user-friendly view.
      You really need an Explorer extension to get all the files. If you play with some script, you can see some of the files in it, although not all of them. By modifying the code you sent you get the files that are "in" the Temporary Internet Files, not the cookie as you can see with Internet Explorer (see Figure 6). However, the best way to manage that kind of folder is to create an Explorer Extension.

Q I have a customer who wants to prompt a user-defined message box through the window.confirm method in the window_onbeforeunload event before Internet Explorer is closed.
  var rtn;
rtn=window.confirm("Close or not?");
if (!rtn)
{
    window.event.retrunValue=false;
}

      The window.confirm method prompts the user with a message box with two buttons, OK and Cancel. When OK is clicked, Internet Explorer will be closed as usual; however, when Cancel is clicked, another system built-in message box will prompt with the following message:
  Are you sure you want to navigate away from this page?
false
Press OK to continue, or Cancel to stay on the current page.

      How can I use my own message box?

A A script may close only those windows which it opened. How would you like it if you went to a Web page that, say, detected you were running Internet Explorer and helpfully closed all your browser windows for you? That's a denial-of-service attackâ€"the script does not own that window, the user does. Therefore, the user gets to decide whether it stays open or not. You should redesign your application so that the user's choices about which windows stay open are honored.
      Also, the window.event.returnValue in an onunload event doesn't take False. It takes a string that will be displayed to the user before the window is unloaded. Rewrite your code like this:
  window.event.returnValue="If you close this, 
                          your changes will be lost.";

      Then, get rid of the confirm statement. If you don't want a warning to be displayed, do not set the event.returnValue.

Q Must Microsoft SQL Serverâ„¢ 2000 and IIS be on same machine to make use of the XML support in SQL Server? I can't get it to work on separate boxes.

A No, they can be on different machines. But if you want to use the integrated Windows NT® security option, both machines have to be running Windows 2000. You either use the HTTP Access configuration tool on the machine running IIS to choose the database instance or the Command string (if you access the data via ADO). Remember though, you do have to have the SQLXML IIS add-in installed on the box that's running IIS. Running the SQL Server 2000 client tools install is usually the easiest way to do that.

Q I want to invoke a command from a JScript-based program using WShell.Run method, and I want the output of the window to be displayed in the same window as the script it is run in. I've heard this is easy to do in the next version of Windows Script Host (WSH). Is it?

A This is a very frequently asked question, and the good news is that in the next version of WSH, which recently shipped as a beta, there will be a new function called Exec, which gives you access to the standard streams of a spawned-off executable. You may write code that takes the output from that standard stream and dumps it to the WSH standard stream.
      To see how this works, take a look at the code in Figure 7.

Q What is the difference between running ASP code using a <SCRIPT RUNAT="SERVER"> blocks and <% %> constructs on Microsoft Internet Information Services (IIS) and Windows NT 4.0. Is there a performance improvement? How does ASP handle code caching between these two?

A <SCRIPT RUNAT="SERVER"> can only contain subroutines, not free-standing code. For each script block, a distinct instance of the script engine is allocated and set to a running state prior to running the main script engine. The result is that any free-standing code in the script block is executed prior to the main script engine. This snippet shows the order in which script will execute:
  <% = "You would expect to see this first" %>
<SCRIPT RUNAT=SERVER>
Response.Write("Surprised to see me first")
</SCRIPT>

Q I'm writing a Visual Basic®-based app that connects to a server and requests a series of Web pages. These Web pages contain JavaScript that uses window.external to make calls into the hosting application. For example the Web page could contain the following:
  function window.onload(){
    window.external.Property("foo") = 'bar';
    window.external.foo("some stuff here...");
}

      Currently, when the page loads in the WebBrowser control, I get an error stating "Object doesn't support this property or method". How can I handle the window.external calls in Visual Basic?

A When a script asks for window.external, Internet Explorer defers the call to a host object that implements the IDocHostUIHandler interface. More precisely, it calls IDocHostUIHandler:GetExternal and asks for an IDispatch * object. Unfortunately, you can't simply implement this interface in Visual Basic. You need a C++ DLL as an intermediary.
      If you search MSDN® for IDocHostUIHandler you'll find some samples. Especially helpful is an article called "Take Total Control of Internet Explorer with Advanced Hosting Interfaces" in the October 1998 issue of Microsoft Internet Developer, and Knowledge Base article Q188015 "HOWTO: Access Methods/Properties of Container From Script".

Got a question? Send questions and comments to webqa@microsoft.com.
Thanks to the following Microsoft developers for their technical expertise: Greg Abbiss, Sue Brazier, Allan Brown, Dale Burris, Mike Christensen, Andrew Clinick, Scott Crenshaw, Brent E. Curtis, Derek Denny-Brown, Sudheer Gangadaranellore, Gary Gu, Howard Hao, Thomas Jeyaseelan, Eric Lippert, Andy Morrison, Simon Mourier, Jay Pillai, Jonmichael Presley, Brenda Potts, Mario Raccagni, Michael Rys, David Schach, John Shipway, Mike Swanson, Peter Torr, Adam Vandenberg, Juanya Williams, Roger Wolter, Vincent Yung.

From the April 2001 issue of MSDN Magazine.