HTML inside VBScript as popup
I looked at Use HTML Tags in VBScript and How can I call a vbscript function from html? but I can't see what is wrong with my code. Can someone review it and tell me why when I click OK the window doesn't close? I commented out some of the lines that I tried and didn't work.
Dim objIE, objShell
Dim strDX
Set objIE = CreateObject("InternetExplorer.Application")
Set objShell = CreateObject("WScript.Shell")
strDX = "AT-0125B"
objIE.Navigate "about:blank"
objIE.Document.Title = "Covered Diagnosis"
objIE.ToolBar = False
objIE.Resizable = False
objIE.StatusBar = False
objIE.Width = 350
objIE.Height = 200
'objIE.Scrollbars="no"
' Center the Window on the screen
With objIE.Document.ParentWindow.Screen
objIE.Left = (.AvailWidth - objIE.Width ) \ 2
objIE.Top = (.Availheight - objIE.Height) \ 2
End With
objIE.document.body.innerHTML = "<b>" & strDX & " is a covered diagnosis code.</b><p> </p>" & _
"<center><input type='submit' value='OK' onclick='VBScript:ClickedOk()'></center>" & _
"<input type='hidden' id='OK' name='OK' value='0'>"
objIE.Visible = True
'objShell.AppActivate "Covered Diagnosis"
'MsgBox objIE.Document.All.OK.Value
Function ClickedOk
'If objIE.Document.All.OK.Value = 1 Then
'objIE.Document.All.OK.Value = 0
'objShell.AppActivate "Covered Diagnosis"
'objIE.Quit
Window.Close()
'End If
End Function
source to share
The function is ClickedOk()
not part of the HTML source of the new window. Your script starts a new Internet Explorer process, but the HTML code (or script) in that process cannot use code from another process (the script process in this case):
yourscript.vbs --> ClickedOk() | ^ | | | X v | iexplore.exe --> <input onclick='VBScript:ClickedOk()'>
You will need IPC methods to communicate with other processes, but browsers usually restrict this kind of access for security reasons.
So, when you click OK, it looks for a function ClickedOK
and cannot find it. So it won't work.
To make it work, try something like this:
objIE.document.body.innerHTML = "<b>" & strDX & " is a covered diagnosis code.</b><p> </p>" & _
"<center><input type='submit' value='OK' onclick='self.close();'></center>" & _
"<input type='hidden' id='OK' name='OK' value='0'>"
source to share