PRB: openWindow in Anchor Tag Fails in Active Desktop Item

ID: Q185372


The information in this article applies to:
  • Microsoft Internet Explorer (Programming) versions 4.0, 4.01
  • Microsoft JScript, versions 1.0, 2.0, 3.0


SYMPTOMS

An Active Desktop item that contains a Web page with a hyperlink in the format <A HREF="javascript:openWindow()> will not work if the openWindow() function opens a new window using window.open(). When you click on the hyperlink that points to the anchor tag listed above, you receive an error from Internet Explorer that indicates that an object is expected. Also, "javascript:openWindow" appears in Internet Explorer's Address box.


CAUSE

The problem is that this method makes some assumptions about the context in which the code will run. In a browser window, this code would look for the openWindow() function within the document itself. Active Desktop items are implemented as IFRAMEs of their parent window. Therefore, on the Active Desktop, this code would not find the openWindow() function.


RESOLUTION

Add an explicit _self reference in your anchor tag like this:


   <A HREF="javascript:openWindow()" TARGET=_self> 


STATUS

This behavior is by design.


MORE INFORMATION

The above code is analogous to right-clicking a javascript:url and choosing to open it in a new window. For example, the following code to open a new window does not work from the Active Desktop:


   <A HREF="javascript:openWindow()">Open a New Window</A>

   <SCRIPT LANGUAGE="JavaScript">
   <!--

      function openWindow()
      {
         window.open("<LINK TYPE="GENERIC" VALUE="http://www.microsoft.com");">http://www.microsoft.com");</LINK>
      }
   //-->
   </SCRIPT> 
When developing for the Active Desktop, never make any assumptions about the context that you are in. For example in this case, the openWindow() function is in the context of the current document. For this to work from the Active Desktop, add an explicit _self reference, like the following:

   <A HREF="javascript:openWindow()" TARGET=_self>Open a New Window</A>

   <SCRIPT LANGUAGE="JavaScript">
   <!--

      function openWindow()
      {
         window.open("<LINK TYPE="GENERIC" VALUE="http://www.microsoft.com");">http://www.microsoft.com");</LINK>
      }
   //-->
   </SCRIPT> 


REFERENCES

For more information, please see the MSDN Web Workshop:

http://msdn.microsoft.com/workshop/default.asp

Additional query words: HREF javascript

Keywords : kbIE400 kbIE401 kbJScript100 kbJScript200 kbJScript300 kbDSupport
Version : WINDOWS:1.0,2.0,3.0,4.0,4.01
Platform : WINDOWS
Issue type : kbprb


Last Reviewed: July 22, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.