Discussion:
InternetExplorer.Application / objShell.Windows + obj.document.parentWindow
(too old to reply)
Richard Stallmann
2007-01-27 20:31:54 UTC
Permalink
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
mayayana
2007-01-27 20:50:15 UTC
Permalink
Post by Richard Stallmann
Also, it would be interesting to convert the entire VB/VBA syntax for the
WebBrowser control to VBScript, since there is no
Post by Richard Stallmann
http://msdn.microsoft.com/workshop/browser/webbrowser/reflist_vb.asp
It's probably there someplace. Things are very hard to
find on microsoft.com in general, and they get moved
around a lot. When you finally do find them, you just
end up going in circles. (As I just did trying to find the
page with document properties from your link.)

I find it's always much better to start at Google than
to actually attempt traversing the Microsoft links.

It's hard to believe the people at MS could be
so out to lunch. I suspect they deliberately obscure
things so that more people will buy the MSDN CDs.

But the bigger question is what's Richard Stallman
doing using IE and VBScript.?! He won't even use
non-OSS Linux software.....or at least so he claims. :)
d***@gmail.com
2007-01-28 01:05:16 UTC
Permalink
How can you read an element value? I need to use a vbs file to read
text input from IE and copy it to a second IE.
Paul Randall
2007-01-28 01:52:31 UTC
Permalink
Post by d***@gmail.com
How can you read an element value? I need to use a vbs file to read
text input from IE and copy it to a second IE.
Here is the root URL for articles about how to use the IE document object
model:
http://msdn.microsoft.com/library/default.asp?url=/workshop/author/om/doc_object.asp

Here is the URL for the reference docment on the IE document object model:
http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/charsets/charset1.asp

In general, element.OuterHtml returns the entire contents of the element,
including the tags that enclose it. InnerHtml returns the same thing
without the tags.
InnerText returns just the text strings within InnerHtml, and is a property
of the following types of elements;
A, ABBR, ACRONYM, ADDRESS, B, BDO, BIG, BLOCKQUOTE, BODY, BUTTON, CAPTION,
CENTER, CITE, CODE, CUSTOM, DD, DEL, DFN, DIR, DIV, EM, FIELDSET, FONT,
FORM, hn, HTML, I, IFRAME, INS, KBD, LABEL, LEGEND, LI, LISTING, MAP,
MARQUEE, MENU, nextID, NOBR, OL, OPTION, P, PLAINTEXT, PRE, Q, RT, RUBY, S,
SAMP, SCRIPT, SELECT, SMALL, SPAN, STRIKE, STRONG, SUB, SUP, TABLE, TBODY,
TD, TEXTAREA, TFOOT, TH, THEAD, TITLE, TR, TT, U, UL, VAR, XMP

-Paul Randall
d***@gmail.com
2007-01-28 03:25:42 UTC
Permalink
Thanks Paul. I don't understand the object model yet but from the
posts above and others else ware I came up with the following code.
Its a perfect start to what I am looking to do. My goal is to extract
customer order information from an administrate page in my store and
send it to the PayPal Virtual Terminal. This will reduce errors from
manual copying of data.

Set oIE_1 = WScript.CreateObject("InternetExplorer.Application")
'Set browser number 1 window properties.
oIE_1.left = 50
oIE_1.top = 50
oIE_1.height = 275
oIE_1.width = 360
oIE_1.menubar = 0
oIE_1.toolbar = 0
oIE_1.statusbar = 0
oIE_1.navigate("about:blank")
Do While oIE_1.Busy : Loop
Set oDoc_1 = oIE_1.Document
oDoc_1.writeln("<HTML><HEAD><TITLE>TITLE TEST 1</TITLE></HEAD>")
oDoc_1.writeln("<BODY><B>TEST 1</B>")
oDoc_1.writeln("<FORM NAME='TESTFORM1'>")
oDoc_1.writeln("<INPUT TYPE='TEXT' NAME='TEXT1'>")
oDoc_1.writeln("<INPUT TYPE='TEXT' NAME='TEXT2'>")
oDoc_1.writeln("</FORM></BODY></HTML>")
oIE_1.visible = 1

Set oIE_2 = WScript.CreateObject("InternetExplorer.Application")
'Set browser number 2 window properties.
oIE_2.left = 450
oIE_2.top = 50
oIE_2.height = 275
oIE_2.width = 360
oIE_2.menubar = 0
oIE_2.toolbar = 0
oIE_2.statusbar = 0
oIE_2.navigate("about:blank")
Do While oIE_2.Busy : Loop
Set oDoc_2 = oIE_2.Document
oDoc_2.writeln("<HTML><HEAD><TITLE>TITLE TEST 2</TITLE></HEAD>")
oDoc_2.writeln("<BODY><B>TEST 2</B>")
oDoc_2.writeln("<FORM NAME='TESTFORM2'>")
oDoc_2.writeln("<INPUT TYPE='TEXT' NAME='TEXT1'>")
oDoc_2.writeln("<INPUT TYPE='TEXT' NAME='TEXT2'>")
oDoc_2.writeln("</FORM></BODY></HTML>")
oIE_2.visible = 1

'Cross read and write from each browser
oDoc_1.testform1.text1.value = "TEST 1 TEXT"
oDoc_2.testform2.text1.value = "TEST 2 TEXT"
oDoc_1.testform1.text2.value = oDoc_2.testform2.text1.value
oDoc_2.testform2.text2.value = oDoc_1.testform1.text1.value
Richard Stallmann
2007-02-03 16:43:31 UTC
Permalink
Bah, turns out you can't intercept events using vbscript, only real VB

Sub objIE_NewWindow3(ppDisp, Cancel, dwFlags, bstrUrlContext, bstrUrl)
'dwFlags => 134=UserInitiated, 6=Click, 4=JavascriptInitiated
Cancel = true ' doesnt work
'End Sub

That's because the the type declarations for the ByRef parameters are missing in VBScript, so you can't return any values. Sux!
Thanx, Microsoft
Post by Richard Stallmann
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
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
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
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
http://msdn.microsoft.com/workshop/browser/webbrowser/reflist_vb.asp
Private Sub object_NavigateError( _
ByVal pDisp As Object, _
ByVal URL As Variant, _
ByVal TargetFrameName As Variant, _
ByVal StatusCode As Variant, _
ByRef Cancel As Boolean)
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
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
http://msdn.microsoft.com/workshop/browser/webbrowser/reference/events/newwindow3.asp
I wonder what the VBScript syntax for this event is
Loading...