首页 > 解决方案 > 使用 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.

标签: javascripthtmljquery

解决方案


推荐阅读