Richard Stallmann
2007-01-27 20:31:54 UTC
Hey, I finally found out how to access the window properties of an InternetExplorer.Application / objShell.Windows objects. First I
thought this wasn't even possible, since the InternetExplorer.Application / objShell.Windows objects basically represent the window
themselves, so the next DOM level is the document:
set objShell = CreateObject("Shell.Application")
set objShellWindows = objShell.Windows
set FirstWindow = objShellWindows.Item(0)
WScript.Echo FirstWindow.document.nodeName
----------------------------------------------------
Set objIE = WScript.CreateObject("InternetExplorer.Application","objIE_")
WScript.Echo objIE.document.nodeName
But on this page:
http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/parentwindow.asp
Microsoft tells us about the parentWindow Property of the document. This way you can move again upwards the DOM to the window object
and access all of its properties:
Set objIE = WScript.CreateObject("InternetExplorer.Application","objIE_")
WScript.Echo objIE.document.parentWindow.name
will return the name of the current Internet explorer window, whereas
WScript.Echo objIE.name
will return the name of the objShell.Windows (="Internet Explorer")
Also, it would be interesting to convert the entire VB/VBA syntax for the WebBrowser control to VBScript, since there is no
reference on MSDN for the VB Scripting edition:
http://msdn.microsoft.com/workshop/browser/webbrowser/reflist_vb.asp
For example, the MSDN VB reference for the NavigateError event of the IE/WebBrowser objects reads as follows:
Private Sub object_NavigateError( _
ByVal pDisp As Object, _
ByVal URL As Variant, _
ByVal TargetFrameName As Variant, _
ByVal StatusCode As Variant, _
ByRef Cancel As Boolean)
In order to use this event in VBScript, it has to look like this:
Sub objIE_NavigateError(pDisp,URL,TargetFrameName,StatusCode,Cancel)
wscript.echo "objIE_NavigateError"
End Sub
Here's a script that will change the name property of the InternetExplorer.Application object every time you open a new document or
download a file:
ON ERROR RESUME NEXT
Set objIE = WScript.CreateObject("InternetExplorer.Application","objIE_")
objIE.Visible = True
objIE.Navigate2 "http://www.google.com"
Do While objIE.Visible
WScript.Sleep 1000
Loop
Sub objIE_NavigateComplete2(pDisp, URL)
objIE.document.parentWindow.name = "_new"
End Sub
Sub objIE_FileDownload(ActiveDocument,Cancel)
if (objIE.Document.all.length > 0) then
objIE.document.parentWindow.name = "_new"
end if
End Sub
Sub objIE_OnQuit()
WScript.Quit
End Sub
I am still trying to get the NewWindow3 Event to fire through VBScript:
http://msdn.microsoft.com/workshop/browser/webbrowser/reference/events/newwindow3.asp
I wonder what the VBScript syntax for this event is
thought this wasn't even possible, since the InternetExplorer.Application / objShell.Windows objects basically represent the window
themselves, so the next DOM level is the document:
set objShell = CreateObject("Shell.Application")
set objShellWindows = objShell.Windows
set FirstWindow = objShellWindows.Item(0)
WScript.Echo FirstWindow.document.nodeName
----------------------------------------------------
Set objIE = WScript.CreateObject("InternetExplorer.Application","objIE_")
WScript.Echo objIE.document.nodeName
But on this page:
http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/parentwindow.asp
Microsoft tells us about the parentWindow Property of the document. This way you can move again upwards the DOM to the window object
and access all of its properties:
Set objIE = WScript.CreateObject("InternetExplorer.Application","objIE_")
WScript.Echo objIE.document.parentWindow.name
will return the name of the current Internet explorer window, whereas
WScript.Echo objIE.name
will return the name of the objShell.Windows (="Internet Explorer")
Also, it would be interesting to convert the entire VB/VBA syntax for the WebBrowser control to VBScript, since there is no
reference on MSDN for the VB Scripting edition:
http://msdn.microsoft.com/workshop/browser/webbrowser/reflist_vb.asp
For example, the MSDN VB reference for the NavigateError event of the IE/WebBrowser objects reads as follows:
Private Sub object_NavigateError( _
ByVal pDisp As Object, _
ByVal URL As Variant, _
ByVal TargetFrameName As Variant, _
ByVal StatusCode As Variant, _
ByRef Cancel As Boolean)
In order to use this event in VBScript, it has to look like this:
Sub objIE_NavigateError(pDisp,URL,TargetFrameName,StatusCode,Cancel)
wscript.echo "objIE_NavigateError"
End Sub
Here's a script that will change the name property of the InternetExplorer.Application object every time you open a new document or
download a file:
ON ERROR RESUME NEXT
Set objIE = WScript.CreateObject("InternetExplorer.Application","objIE_")
objIE.Visible = True
objIE.Navigate2 "http://www.google.com"
Do While objIE.Visible
WScript.Sleep 1000
Loop
Sub objIE_NavigateComplete2(pDisp, URL)
objIE.document.parentWindow.name = "_new"
End Sub
Sub objIE_FileDownload(ActiveDocument,Cancel)
if (objIE.Document.all.length > 0) then
objIE.document.parentWindow.name = "_new"
end if
End Sub
Sub objIE_OnQuit()
WScript.Quit
End Sub
I am still trying to get the NewWindow3 Event to fire through VBScript:
http://msdn.microsoft.com/workshop/browser/webbrowser/reference/events/newwindow3.asp
I wonder what the VBScript syntax for this event is