PRB: The Window.open File Within HREF Returns [OBJECT] in Current Window (257321)



The information in this article applies to:

  • Microsoft Internet Explorer (Programming) 4.0
  • Microsoft Internet Explorer (Programming) 4.01
  • Microsoft Internet Explorer (Programming) 4.01 SP1
  • Microsoft Internet Explorer (Programming) 4.01 SP2
  • Microsoft Internet Explorer (Programming) 5
  • Microsoft Internet Explorer (Programming) 5.01
  • Microsoft Internet Explorer (Programming) 5.5

This article was previously published under Q257321

SYMPTOMS

The browser window's page disappears and is replaced by the word "[object]" when you use the following code to open a new window from an HREF:

<a href="javascript:window.open('http://www.microsoft.com');">Click here</a>
				

CAUSE

This problem occurs because the browser is navigating to the window object returned by the Window.open file call.

This behavior is by design.

RESOLUTION

To resolve this problem, perform one of the following:
  • Add a void (0), as illustrated here, to give a no return value:
    <a href="javascript:window.open('http://www.microsoft.com'); void(0)">Click here</a>
    					
    -or-

  • Call your own JScript function to open a new window. This prevents the hyperlink navigation and allows you to retain a reference to the opened window.
    <SCRIPT>
    
    var childWin;
    
    function OpenUrl(url) {
    	childWin = window.open(url);
    }
    
    </SCRIPT>
    
    <a href="javascript:OpenUrl('http://www.microsoft.com');">Click here</a><p>
    						

REFERENCES

For more information about developing Web-based solutions for Microsoft Internet Explorer, visit the following Microsoft Web sites:

Modification Type:MajorLast Reviewed:5/11/2006
Keywords:kbprb kbScript KB257321