C# 获取最近javascript警报的文本

C# 获取最近javascript警报的文本,c#,javascript,text,alert,mshtml,C#,Javascript,Text,Alert,Mshtml,我正在使用mshtml编写IE扩展。有没有办法(通过C#或javascript)获取显示给用户的最近警报的文本 提前感谢。如果您可以劫持/注入/执行网站中的任何JS,您可以使用自定义方法覆盖警报方法,该方法调用内部的原始方法:)类似于以下内容: // let's save the alert first var _super_original_alert = window.alert; // and now we overwrite it window.alert = function(s){

我正在使用mshtml编写IE扩展。有没有办法(通过C#或javascript)获取显示给用户的最近警报的文本


提前感谢。

如果您可以劫持/注入/执行网站中的任何JS,您可以使用自定义方法覆盖警报方法,该方法调用内部的原始方法:)类似于以下内容:

// let's save the alert first
var _super_original_alert = window.alert;
// and now we overwrite it
window.alert = function(s){
  // do something with the received string
  // i will just log it, but you might want to send the string via
  // ajax/jsonp to a remote server
  console.log(s)

  // call the original intended alert
  _super_original_alert(s)
}

这不太好,但可以做到。

为什么不保存之前发出的警报?实际上,我正在为网站编写一个监视器,我的应用程序只是跟踪用户的步骤。因此,我不知道如何找出任何行动的结果中是否出现了警报。你能将js注入该网站吗?非常感谢。我想这正是我所需要的,即使页面上有jquery,它也能工作吗?另外,我们可以应用相同的逻辑进行确认吗?有人可以更新此以确认吗?或者验证我的代码
var oldconfirm=window.confirm;window.confirm=function(msg){document.\uuuuu LastConfirm=msg;console.log(msg);return oldconfirm(msg)}
这里我试图将msg存储为document属性,以便以后可以访问它。var oldconfirm=window.confirm;window.confirm=函数{window.lastConfirmationMessage=s;返回oldConfirm};确认(“omnom”);window.lastConfirmationMessage=>'omnom'还有一个问题。我能够使用您提供的警报方法,但在某些页面上,它会出现错误,比如太多递归。我不能理解它。尽管它有效。但现在真正的问题来了。此警报出现在页面上的submit操作之后,当我单击submit时,它会验证某些内容,然后显示警报消息,如say so and so object is created successfully。当我看到控制台时,日志语句不会显示。此外,单击OK按钮后,浏览器窗口本身被关闭,所以我无法获取文本。你知道在Firefox中从alert获取文本的更好方法吗?