有没有办法模拟JavaScript中的警报点击? [英] Is there a way to simulate a click on an alert in JavaScript?

查看:95
本文介绍了有没有办法模拟JavaScript中的警报点击?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含iframe的页面,其源页面位于一个单独的域中。源页面会不时生成警报。当它这样做时,它会停止正在进行的操作,直到用户单击确定到警报。

I have a page with an iframe whose source page is in a separate domain. From time to time, the source page generates an alert. When it does so, it stops what it is doing until the user clicks OK to the alert.

我想要的是以编程方式单击此警报上的确定,以便源页面可以恢复有用。这可能吗?

What I would like to do is programmatically click OK on this alert so the source page can get back to being useful. Is this possible?

推荐答案

JavaScript是单线程的,这意味着当你调用一个函数时,它会一直阻塞直到它返回。当你调用alert()时,它会将控制传递给浏览器,浏览器决定如何处理它。弹出UI对话框的不是Javascript,而是浏览器。 alert()在浏览器收到OK事件并返回控件之前不会返回。 javascript线程暂停,直到发生这种情况。

JavaScript is single-threaded, which means when you call a function, it blocks until it returns. When you call alert(), that passes control to the browser which decides how to handle it. It is not Javascript which is popping the UI dialog, it is the browser. alert() does not return until the browser receives the "OK" event and returns control. The javascript thread is halted until that happens.

因此,至少有上述段落中所述的两个不同原因,答案是 :)

So for at least two different reasons stated in the above paragraph, the answer is no :)

这篇关于有没有办法模拟JavaScript中的警报点击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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