【问题标题】:Checking whether realm in the authentication dialog contains a string检查身份验证对话框中的领域是否包含字符串
【发布时间】:2012-07-02 20:37:44
【问题描述】:

我正在尝试检查来自 Firefox 身份验证对话框的网站领域是否包含指定的字符串:

document.getElementById("prompt-password-message").textContent.indexOf("STRING")

其中 STRING 是我要查找的字符串。

任何想法为什么上面的代码不起作用?

【问题讨论】:

  • 如果你 console.log(document.getElementById("prompt-password-message").textContent); 你会得到什么?
  • 你确定document.getElementById("prompt-password-message") 正在返回任何东西吗? iirc 在附加组件/扩展中进行 DOM 操作的非标准方法

标签: javascript firefox firefox-addon xul


【解决方案1】:

您需要获取“内容文档”,否则 getElementById() 将不返回任何内容...

https://developer.mozilla.org/En/Working_with_windows_in_chrome_code#Accessing_content_documents

content.document.getElementById("prompt-password-message").textContent.indexOf("STRING")

【讨论】:

  • 不知道为什么它对 OP “有效”,但他实际上指的是 element of a XUL document,而不是内容文档中的内容。这只是意味着这个问题缺少比显而易见的更多信息。
  • 啊,好吧,这是在黑暗中刺伤。工作量不大。
猜你喜欢
  • 2015-02-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-06-27
  • 1970-01-01
  • 2011-01-21
  • 2012-06-23
  • 1970-01-01
相关资源
最近更新 更多