Re: window.close method self.document issue

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Michael Harris \(MVP\) (mikhar_at_mvps.org)
Date: 11/01/04


Date: Mon, 1 Nov 2004 13:08:13 -0800

Stuntace wrote:
> I have here some simple wmi script that outputs vga card info within
> an hta. Unfortunately the window.close method and
> self.document don't seem to play nice together.
> window.close is never initiated while self.document is used here.
> Please try the below code here in an .hta with and without below line.
> Set objDocument = self.Document
> Note: without above, script produces obvious error, but does
> demonstrate behaviour difference.
>
> Any clues or even good guesses are appreciated. Thanks.

As soon as you call objDocument.open, you begin completely rewriting the
entire current document. None of the original content, including the script
elements, will survive.

Give that you make the call...

    Pre1.innerText = videoinfo();

videoinfo() should be defined as a Function (not a Sub) that builds up the
content to assign to Pre1innerText as an ordinary concatenated string with
appropriate vbCrLf's where you want line breaks.

Of course, you *could* re-write this so that you don't mix languages as well
as make it a little less convoluted ;-)...

>
>
> HTML>
> <HEAD>
> <TITLE>HTTP video info</TITLE>
> <HTA:Application
> APPLICATIONNAME="video info"
> Border = Thick
> BorderStyle = Complex
> CAPTION="yes"
> ICON=""
> ShowInTaskBar = No
> MaximizeButton = No
> MinimizeButton = Yes
> SINGLEINSTANCE="no"
> SYSMENU="yes"
> VERSION="1.0"
> WINDOWSTATE="normal"
> >
>
> <SCRIPT language="JScript">
> function window.onload()
> {
> window.resizeTo(510,210);
> Pre1.innerText = videoinfo();
> }
> </SCRIPT>
>
> </SCRIPT>
> <SCRIPT Language="JScript">
> function exit()
> {
> window.close();
> }
> </SCRIPT>
>
>
>
> <SCRIPT LANGUAGE="VBScript">
>
> Sub videoinfo()
>
> Set objDocument = self.Document
> objDocument.open
>
> Dim strMsg, strComputer
>
> strComputer = inputbox ("Enter a valid PC netbios name", "Remote
> page file information retrieval")
>
> if strComputer = "" then
> strcomputer = "."
> else
> end if
>
> <!-------------- Collect video info WMI--------------->
> Set objWMIService = GetObject("winmgmts:" &
> "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
> Set colItems = objWMIService.ExecQuery( "Select * from
> Win32_DisplayConfiguration", , 48 )
>
> <!---------------- Ready output ----------------------->
> For Each objItem in colItems
>
> objdocument.WriteLn "VideoCard : "
> objdocument.WriteLn objItem.DeviceName & "<br>"
> objdocument.WriteLn "XResolution : "
> objdocument.WriteLn objItem.PelsWidth & "<br>"
> objdocument.WriteLn "YResolution : "
> objdocument.WriteLn objItem.PelsHeight & "<br>"
> objdocument.WriteLn "BitsPerPel : "
> objdocument.WriteLn objItem.BitsPerPel & "<br>"
> objdocument.WriteLn "VRefresh : "
> objdocument.WriteLn objItem.DisplayFrequency
> Next
>
> End Sub
>
> </SCRIPT>
>
> </HEAD>
>
> <BODY onclick="exit()">
> <PRE ID=Pre1> </PRE>
> </BODY>
> </HTML>

-- 
Michael Harris
Microsoft.MVP.Scripting

Quantcast