简体   繁体   English

从VBA清除Javascript消息框

[英]Clear Javascript Message Box from VBA

In controlling a website (with VBA), and attempting to delete all of the selected items in a table, I get a Javascript pop-up which asks me if I really want to delete all of them (OK or Cancel). 在控制网站(使用VBA)并尝试删除表中的所有选定项时,我看到一个Javascript弹出窗口,询问我是否真的要删除所有这些项(“确定”或“取消”)。 When this pops up, my vba code stops, and will not do anything else, until a human clicks the button. 当这个弹出窗口时,我的vba代码停止,并且除非有人点击按钮,否则将不会执行任何其他操作。

I have researched this quite a bit, and it seems that changing the onClick event for the HTML button would in theory work, but I have been unable to get it to work as of yet. 我对此进行了相当多的研究,似乎从理论上讲可以更改HTML按钮的onClick事件,但是到目前为止,我还无法使其正常工作。 Below is the HTML code for the button, the subsequent Javascript code, and then my VBA code. 以下是按钮的HTML代码,后续的Javascript代码,然后是我的VBA代码。

HTML Button HTML按钮

 <p>Delete:&nbsp;<input type="button" name="button_Delete" value="Delete" onclick="doDelete('c');">&nbsp;<span class="note">Deletes all selected charts.</span></p> <p>Move to:&nbsp;<select id="select_Lists" name="select_Lists"> 

Javascript after HTML Button HTML按钮后的Javascript

 <a href="javascript:doDeleteList('169', 'C');">Delete List</a> | 

VBA Code to Delete all selected from HTML Table VBA代码删除从HTML表中选择的所有内容

Dim ieDelete as HTMLInputButtonElement
SetieDelete = IE.Document.getElementsByName("button_Delte")(0)
Sleep(500)
ieDelete.removeAttribute("onClick")
Sleep(500)
ieDelete.setAttribute "onClick", "return true;"
Sleep(500)
ieDelete.Click

When running the VBA as is, it continues to bring up the Javascript message box. 按原样运行VBA时,它将继续显示Javascript消息框。 I have attempted adding ieDelete.setAttribute "onClick", "" , but that ends up deleting the entire event, I was not able to do anything to it after that. 我尝试添加ieDelete.setAttribute“ onClick”,“” ,但最终删除了整个事件,此后我无能为力。

And... For the record, I also saw a post describing another option, but I couldn't figure out how to use it in my scenario. 并且...作为记录,我还看到了描述另一种选择的帖子,但我不知道如何在我的场景中使用它。 Respond to Website Message Box by Automating InternetExplorer with VBA 通过使用VBA自动化InternetExplorer来响应网站消息框

Thanks in advance for the assistance. 在此先感谢您的协助。

You could possibly hack the confirmation dialog itself: Overwrite the builtin javascript confirm function using the following VBA code before calling ieDelete.Click : 您可能会修改确认对话框本身:在调用ieDelete.Click之前,使用以下VBA代码覆盖内置的javascript confirm函数。

IE.Document.parentWindow.execScript "confirm = function() { return true; }"

(Insert it before your call to ieDelete.Click ) (在调用ieDelete.Click之前将其ieDelete.Click

This will cause the browser to automatically 'click' OK whenever a confirmation dialog is requested. 每当请求确认对话框时,这将导致浏览器自动“单击”“确定”。

PS: This answer assumes that the following: PS:此答案假定以下内容:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM