Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Close IE window that was opened thru VBScript

Status
Not open for further replies.

markronz

IS-IT--Management
Mar 20, 2007
93
US
Hello Everyone-
I am trying to find a way to close out of an IE window that my VBScript opened. Here is basically my code so far:

Set objExplorer = CreateObject("InternetExplorer.Application")
objExplorer.Visible = True
objExplorer.ToolBar = False
objExplorer.StatusBar = False
objExplorer.Navigate "about:blank"
objExplorer.Document.Body.InnerHTML = "<p>Assist Complete. <i>(You may now close this window.)</i></p><p><BUTTON TYPE=BUTTON NAME=""Close"" onClick=""window.close()"">Close </BUTTON></p>"

Do While TypeName(objExplorer) = "IWebBrowser2"
WScript.Sleep 1000
Loop
WScript.Echo "More code follows after the window is closed"



So I just need to find a good way to close the window. Does anyone have any suggestions? Like is there a way to assign a normal ?sub/method? to the Close button in my window? So that when the user clicks on the button it runs that code. If I could do that then I could just have my VBScript use SendKeys to send a ALT+F4 to close the window.

Or am I looking at this the complete wrong way? Any help would be appreciated.

Thanks!
-Mark

P.S. As you can see above in my code, I tried to attach the Window.Close() to the Close button. The reason this doesn't work right is because it prompts the user if they want to close the window. I just want it to close, no questions asked.
 
Try this.

Code:
Set objExplorer = CreateObject("InternetExplorer.Application")
objExplorer.Visible = True
objExplorer.ToolBar = False
objExplorer.StatusBar = False
objExplorer.Navigate "about:blank"
objExplorer.Document.Open 
objExplorer.Document.Write "<html><head>" & VbCrLf & _
"<script language=""vbscript"">Dim Button : Button = 0</script>" & VbCrLf & _
"</head><body><p>Assist Complete. <i>(You may now close this window.)</i></p>" & _
"<p><BUTTON TYPE=BUTTON NAME=""Close"" onClick=""Button = 1"">Close</BUTTON></p></body></html>"
objExplorer.Document.Close

Do While TypeName(objExplorer) = "IWebBrowser2"
	intButton = objExplorer.Document.parentWindow.Button
	If intButton = 1 Then
		objExplorer.Quit
		Exit Do
	End If
    WScript.Sleep 1000
Loop
WScript.Echo "More code follows after the window is closed"

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
FANTASTIC! That solves a good portion of my problems. Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top