javascript - 使用 indexOf 在 iframe 中搜索内容
问题描述
基本上我试图在 iframe 中找到某些文本,我在控制台中没有错误,我不知道我在这里做错了什么。我正在尝试使用 indexOf,因为如果我不在 iframe 内搜索,它会很好用。我尝试在此处使用此帖子进行添加->如何在 Javascript 中获取 iframe 的正文内容?但一直不工作。有人可以给我和手吗?
setTimeout(function() {
var iframe = document.getElementById('aspxcontent');
var iframeDocument = iframe.contentDocument || iframe.contentWindow.document;
var iframeContent = iframeDocument.getElementById('DialogMainBody');
[].slice.call(document.querySelectorAll('pre'), 0).forEach(function(aEl) {
if (aEl[iframeContent].indexOf('update') > -1) {
console.log("found");
}else{
console.log("not found");
}
});
}, 5000);
编辑 1
var x = document.getElementsByTagName("iframe")[0].contentWindow;
//x = window.frames[0];
x.document.getElementsByTagName("body")[0].style.backgroundColor = "blue";
// this would turn the 1st iframe in document blue.
解决方案
推荐阅读
- python-3.x - 无法在 AWS 胶水端点机器 (PyCharm) 中导入模块 pysftp
- microsoft-information-protection - MIP SDK:将敏感标签应用于 Doc 文件,无法打开
- c++ - 如何在 C++Builder 中拆分 UnicodeString
- bigdata - 如何通过 Airflow 最好地回填多年的数据
- paypal-sandbox - PayPal IPN 问题(沙盒环境),
- sql - 在最近的日期查找最新的
- node.js - npm install express-generator -g 错误:EACCES:权限被拒绝,访问“/usr/lib/node_modules”
- python - 使 Dataset 类遍历所有文件
- grafana - Istio+Grafana 101:为什么不在网格中的服务出现在 Mesh Dashboard 上?
- jenkins - Jenkins 的调试模式