Reputation: 403
I've 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 look it over and let me know why, when I click the OK button, the window doesn't close? I commented some lines out that I've 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
Upvotes: 0
Views: 2165
Reputation: 15370
The ClickedOk()
function is not part of the HTML source code of the new window. Your script starts a new Internet Explorer process, but HTML (or script) code in that process cannot use code from another process (in this case the script process):
yourscript.vbs --> ClickedOk()
| ^
| |
| X
v |
iexplore.exe --> <input onclick='VBScript:ClickedOk()'>
You'd need IPC methods for communicating with other processes, but browsers usually restrict this kind of access due to security considerations.
So, when you click 'OK', it looks for a ClickedOK
function and cannot find it. Thus it will not 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'>"
Upvotes: 2