I have a javascript function that I'd like to call after writing to
about:blank (.Navigate2 "about:blank") but I don't know how to kick
the javascript function off from vbscript -- any ideas here? (see code
below - watch for extra line breaks...). I tried a couple of things
but was unable to get the script to execute...


CODE FOLLOWS:


Option Explicit
Dim objIE, objFSO, objFile, objTargetFile, objWin, strFileName,
strTargetFileName, strArrFiles(), bCopyNeeded, tBegin, tEnd, tDiff,
strMsg
Const STR_TARGET =3D "myTargetPath"
Redim Preserve strArrFiles(0)
strArrFiles(UBound(strArrFiles)) =3D "File1"
Redim Preserve strArrFiles(UBound(strArrFiles) + 1)
strArrFiles(UBound(strArrFiles)) =3D "File2"
Redim Preserve strArrFiles(UBound(strArrFiles) + 1)
strArrFiles(UBound(strArrFiles)) =3D "FileN"


Set objFSO =3D CreateObject("Scripting.FileSystemObject")


If objFSO.FolderExists(STR_TARGET) Then 'Do nothing
Else
objFSO.CreateFolder(STR_TARGET)
End if


Set objIE =3D CreateObject("InternetExplorer.Application")
With objIE
.Navigate2 "about:blank"
.TheaterMode =3D True 'Being browser to the top...
.Toolbar =3D False
.Menubar =3D False
.Statusbar =3D False
.AddressBar =3D False
.Resizable =3D False
Do While (.Busy)
Wscript.Sleep 50
Loop
.Document.Body.style.cursor =3D "wait"
.Document.Body.InnerHTML=3D"<div style=3D'text-
align:center'><div
id=3Dtext style=3D'position:relative;top:35%;z-index:100;font-
family:Tahoma;font-size:14pt;font-weight:bold;text-
align:center;'>Please wait...<br/><br/><br/><span id=3D'meter'></
span></
div></div><script type=3D'text/javascript'>var arrTumble =3D new
Array('|','|','|','|','|','|','|','|','|','|','|','|','|','|','|','|','|','=
=AD|','|','|','|','|','|','|','|','|','|','|','|');var
objTimeout;var counter=3D0;function startProgress() {objTimeout =3D
setTimeout('changeProgress()', 0);}function changeProgress() {var
objSpan =3D document.getElementById('meter');if (objSpan)
{arrTumble[counter]=3D'&nbsp;';objSpan.innerHTML =3D
arrTumble.join('');arrTumble[counter]=3D'|';counter=3D(counter
+1)%30;objTimeout =3D setTimeout('changeProgress()',
100 );}}startProgress();</script>"
.Visible =3D True
' .Document.execScript("startProgress();") '******HERES
MY QUESTION****** - how do I kick off the startProgress() or
changeProgress() javascript functions written to
Document.Body.InnerHTML above?
tBegin =3D Time
For Each strFileName in strArrFiles
strTargetFileName =3D Right(strFileName,
Len(strFileName)-
(InstrRev(strFileName, "\")))
Set objFile =3D objFSO.getFile(strFileName)
'wscript.echo "strFileName=3D" & strFileName &
vbTab & "(" &
Cstr(objFile.Size) & " bytes)"
If objFSO.FileExists(STR_TARGET &
strTargetFileName) Then
Set objTargetFile =3D
objFSO.getFile(STR_TARGET & strTargetFileName)
'wscript.echo "strTargetFileName=3D" &
strTargetFileName & vbTab &
"(" & Cstr(objTargetFile(" & STR_TARGET & strTargetFileName &
").Size)
& " bytes)"
if objFile.Size =3D objTargetFile.Size
Then 'Do Nothing
'wscript.echo "objFile(" &
strFileName & ").Size=3D" & objFile.Size
& vbnewline & "objTargetFile=3D" & objTargetFile.Size
Else
'wscript.echo "delete file + "
& vbnewline & objFSO.CopyFile " &
strFileName & ", " & STR_TARGET & strTargetFileName
objFSO.DeleteFile STR_TARGET &
strTargetFileName, true
objFSO.CopyFile strFileName,
STR_TARGET & strTargetFileName
End If
Else
'wscript.echo "objFSO.CopyFile " &
strFileName & ", " & STR_TARGET
& strTargetFileName
objFSO.CopyFile strFileName,
STR_TARGET & strTargetFileName
End If
Next
tEnd =3D Time
tDiff =3D DateDiff("s", tBegin, tEnd)
If tDiff >=3D 60 Then
strMsg =3D (tDiff \ 60) & " minute"
if (tDiff \ 60) <> 1 Then
strMsg =3D strMsg & "s"
End If
tDiff =3D tDiff Mod 60
strMsg =3D strMsg & " and " & tDiff & " second"
If tDiff <> 1 Then
strMsg =3D strMsg & "s"
End If
Else
strMsg =3D tDiff & " second"
if tDiff <> 1 Then
strMsg =3D strMsg & "s"
End If
End If
.Document.Body.style.cursor =3D "default"
.Document.Body.InnerHTML =3D"<script type=3D'text/
javascript'>function
btnOK_Click() {Window.close();}</script><div
style=3D'position:relative;top:42%;text-align:center;'><span
style=3D'font-
family:Tahoma;font-size:14pt;font-weight:bold;'>Install Complete! ("
&
strMsg & ")<br/><br/></span><br/><br/><br/><br/><br/><span
style=3D'font-
family:Tahoma;font-size:12pt;font-weight:bold;'>Click OK to
continue</
span><br/><input id=3D'btnOK' type=3D'button' value=3D' OK '></div>"
.Document.All.btnOk.onclick =3D getRef("btnOK_Click")
End With
While Not (objIE Is Nothing)
WScript.sleep 100
WEnd


Sub btnOK_Click
objIE.Quit
Set objIE =3D Nothing
End Sub


WScript.Quit(1)

Re: How do I execute a javascript function in an InternetExplorer.Application from vbscript? by itsmillertime4u

itsmillertime4u
Wed Jun 20 09:48:32 CDT 2007

I'm not sure if this would work since your navigating to about:blank
and then using .Document.Body.InnerHTML to write in all your code, but
you may want to look at writing the startProgress() into
Window_OnLoad().

I use this to execute a script immediately after being
launched.......however I write my code to an htm file and then
navigate to the htm file that I just dynamically created, which you
may have to do if this doesn't work. Another alternative is to put all
of the code into an HTA, it won't run in a browser, but you get all
the functionality of a browser.


Re: How do I execute a javascript function in an InternetExplorer.Application from vbscript? by hzgt9b

hzgt9b
Wed Jun 20 10:23:25 CDT 2007

I'd I've never used HTA's but I'm open to it...
Can you point me to some resources on building HTA (or better yet, an
example)

Thanks


Re: How do I execute a javascript function in an InternetExplorer.Application by Ayush

Ayush
Wed Jun 20 10:21:50 CDT 2007

[hzgt9b] wrote-:
> I have a javascript function that I'd like to call after writing to
> about:blank (.Navigate2 "about:blank") but I don't know how to kick
> the javascript function off from vbscript -- any ideas here? (see code
> below - watch for extra line breaks...). I tried a couple of things
> but was unable to get the script to execute...

Use Navigate method to navigate to
javascript:functionName()

Exmaple:
IEObj.Navigate("javascript:alert()")


Good Luck, Ayush.
--
Scripting- your first steps :
http://www.microsoft.com/technet/scriptcenter/topics/beginner/firststeps.mspx