VBScript 中的 HTML 作为弹出窗口 [英] HTML within VBScript as a popup

查看:38
本文介绍了VBScript 中的 HTML 作为弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看过在VBScript中使用HTML标签如何从 html 调用 vbscript 函数?,但我可以不知道我的代码有什么问题.有人可以查看并告诉我为什么当我单击确定"按钮时窗口没有关闭?我评论了一些我尝试过但没有奏效的行.

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>&nbsp;</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

推荐答案

ClickedOk() 函数不是新窗口的 HTML 源代码的一部分.您的脚本启动了一个新的 Internet Explorer 进程,但该进程中的 HTML(或脚本)代码不能使用来自另一个进程(在本例中为脚本进程)的代码:

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()'>

您需要 IPC 方法与其他进程通信,但浏览器通常会限制出于安全考虑,这种访问方式.

You'd need IPC methods for communicating with other processes, but browsers usually restrict this kind of access due to security considerations.

因此,当您单击确定"时,它会查找 ClickedOK 函数但找不到它.因此它不起作用.

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>&nbsp;</p>" & _
"<center><input type='submit' value='OK' onclick='self.close();'></center>" & _
"<input type='hidden' id='OK' name='OK' value='0'>"

这篇关于VBScript 中的 HTML 作为弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆