Prev: script for notifying users when server is on UPS
Next: basic vbscript to open and read an Excel file crashes on closing E
From: Mayayana on 18 Jul 2010 22:05 | The 3d msgbox generates an error message as follows: | Object doesn't support this property or method: | 'objShellWindows.item(...).document.documentElement' | Code: 800A01B6 | Source: Microsoft VBScript runtime error | | Why does it generate that error message? I copied | "document.documentElement.innerHTML" directly from | http://msdn.microsoft.com/en-us/library/ms533739(v=VS.85).aspx | | What am I doing wrong? | Maybe nothing. Microsoft has screwed things up about as much as they possibly could. DocumentElement was added to conform to standard W3C DOM, as of IE6, I think. Prior to that the IE object model has been unique. When MS updated it they added the "quirks mode" option. The gist of it is that if you use a specific DOCTYPE tag in your webpage, IE will interpret the HTML in accord with it's latest update. If you use no DOCTYPE tag, or one of several variants, the page is interpreted in quirks mode -- roughly equivalent to normal IE5 rendering. That was great. The problem is that it can only be one or the other. DocumentElement won't work in quirks mode and non-standard BODY properties will no longer work in standards mode! So you have to figure out whether the page is standards mode or not. There's a new property called document.compatMode. See if the following works. It tests for compatMode and acts accordingly. It also filters so that only IE pages are processed. But it does not filter for "file:". You'll need to deal with that part. fnShellWindowsItemVB Sub fnShellWindowsItemVB() Dim objShell Dim objShellWindows Dim i, IE Set objShell = CreateObject("shell.Application") Set objShellWindows = objShell.Windows If objShellWindows.count > 0 Then For i = 0 to objShellWindows.count - 1 Set IE = objShellWindows.item(i) If InStr(1, typename(IE.document), "html", 1) > 0 Then MsgBox "Path: " & IE.path MsgBox "LocationURL: " & IE.LocationURL MsgBox IE.document.compatMode If IE.document.compatMode = "CSS1Compat" Then MsgBox IE.document.documentElement.innerHTML Else MsgBox IE.document.body.innerHTML End If End If Next Set IE = Nothing Else MsgBox "No windows open." End If Set objShellWindows = Nothing Set objShell = Nothing End Sub
From: Mayayana on 18 Jul 2010 22:16 I'm just answering a couple things in this post that I didn't address in my most recent post.... | 1. Where can I get some education about the "TypeName" thingee? That's a strange one. It's documented but not commonly used. TypeName returns the data type of a variant variable. It's handy for objects because it returns the object name. But for non-object variables VarType is more useful. For instance: s = "ok" ' TypeName(s) returns "String". VarType(s) returns 8. I presume that all | windows satisfying condition (i) will also satisfy this condition: If | InStr(1, sType,"htmldocument", vbTextCompare) <> 0 That should work, yes. I like to just test for "html" in case some IE versions don't use exactly that word. | Lastly, my goal is to make a vbscript's arguments function as though they | could be used byVal or byRef (by sending the information back to the calling | script through a hidden window with a specific title, that the calling script | can use to identify the hidden window containing the return info, which the | calliing script will harvest from the hidden window, and then terminate the | hidden window (to avoid overloading the system with too many open windows.). I'm not sure I follow that. You want to manipulate a hidden IE window to use as a sort of clipboard? I think it should work, if you're doing what I think you're doing. An IE instance also has a unique HWND property (numeric), in case that's useful.
From: Tom Lavedas on 19 Jul 2010 08:47 On Jul 18, 7:38 pm, MarceepooNu <mbh2...(a)aol.com> wrote: > Whoops. > I meant... > > 2. I'm trying to use one function to do three things: > (i) and (ii): Find windows satisfying the conditions: > For Each window in sa.windows > If left(window.LocationUrl, 5) <> "file:" Then > ' logic for selecting windows goes here > If window.locationUrl = "about:blank" Then > and > (iii) within the group of windows satisfying conditions (i) and (ii), find > windows > having certain text (e.g., "Boopsie") in "IE.document.body.innerText" > > Sorry for the typo. > > -- > MarceepooNu {snip} I played with this concept a while back, though I first say Michael Harris post on this subject about ten years ago. He dubbed it 'IEPipes' back then. Others added to the concept. I revisited it recently in response to some other thread in this ng. Anyway, here is my effort in the form of a very simple example (using one script to simulate multiple scripts). It illustrates the use of the enabling functions. '-------------- Code Starts --------------- ' Create a named IE pipe set oPipe1 = MakeIEPipe("ScriptB") ' Send text by way of the body of the IE pipe oPipe1.document.write "Some text." 'Instantiate a new variable in the pipe DimVar "v", oPipe1 ' Set its value, for example the WScript object SetVar "v", wsh, oPipe1 ' Get a new reference to the pipe (as if in another script) if GetIEPipe("ScriptB", oPipe2) then ' list the text content of IE pipe wsh.echo oPipe2.document.body.innertext ' Get an object variable passed through the pipe set newWSH = getvar("v", oPipe2) wsh.echo typename(newWSH), newWSH.name ' Set a new variable through second pipe - a string DimVar "v2", oPipe2 SetVar "v2", "New text", oPipe2 ' And access it through the original Pipe wsh.echo getvar("v2", opipe1) else wsh.echo "Pipe not found" end if Sub DimVar(sVarName, oPipe) with eval("oPipe.document.all." & oPipe.document.title) .text = .text & vbCRLF & "dim " & sVarname end with end sub Function GetVar(sVarName, oPipe) with oPipe.document.parentWindow if isObject(eval("." & sVarname)) then set GetVar = eval("." & sVarname) else GetVar = eval("." & sVarname) end if end with end function Sub SetVar(sVarName, value, oPipe) with oPipe.document.parentWindow if isObject(value) then Execute "set ." & sVarname & "=value" else Execute " ." & sVarname & "=value" end if end with end sub Function MakeIEPipe(sPipeName) Dim oIE if sPipeName = "" then sPipeName = "Blank" set oIE = createobject("InternetExplorer.Application") oIE.navigate "about:blank" Do until oIE.ReadyState = 4 : wsh.sleep 50 : Loop oIE.document.writeln "<html><head><title>" & sPipeName & "</title>" _ & "<script id=" & sPipeName & " language=vbs></ script>" _ & "</head><body></body></html>" set MakeIEPipe = oIE end function ' MakeIEPipe Function GetIEPipe(sPipeName, oIEPipe) Dim w for each w in createobject("shell.application").windows if instr(1, typename(w.document),"html", vbTextCompare) > 0 then if instr(1, w.document.title, sPipeName, vbTextCompare) = 1 then set oIEPipe = w end if end if next GetIEPipe = isObject(oIEPipe) end Function ' GetIEPipe ----------------- Code Ends ------------------ _____________________ Tom Lavedas
From: Mayayana on 19 Jul 2010 17:07
| Microsoft has screwed things up about as | much as they possibly could. DocumentElement was added | to conform to standard W3C DOM, as of IE6, I think. I just discovered another wrinkle in this issue, but probably not one you have to worry about. Document.compatMode is relevant from IE6 up. If you might deal with IE5 you probably need error trapping for that property. Unfortunately, dealing with compatMode requires checking all of your code in both standards compliant and quirks mode webpages, then writing branching code to deal with both. The new wrinkle is that MS has deprecated compatMode in IE8!! The new property is documentMode: http://msdn.microsoft.com/en-us/library/cc196988(v=VS.85).aspx If documentMode = 5 then 'quirks Else standards mode End If Fortunately, compatMode is only deprecated and not broken, so documentMode should not be necessary for the forseeable future. What Microsoft should have done was to have standards mode and quirks mode in HTML/CSS for *rendering*, where it's supposed to be, and left the scripting object model backward compatible. Instead they actually took the trouble to remove support for non-standard DOM properties and methods in the IE scripting DOM. None of this is really a problem for people writing webpages -- they can choose to use standards mode or quirks mode. But for someone dealing with unknown webpages in IE or in a WebBrowser control it means using (and identifying) two separate DOMs. |