0

Basicly im trying to find certain text inside iframe, i get no errors in console, i have no clue what im doing wrong in here. Im trying to use indexOf because if Im not searching inside iframe it works good. I tried to addapt using this post here -> How to get the body's content of an iframe in Javascript? but keeps not working. Can someone give me and hand?

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);

edit 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.
Antony
  • 3
  • 6
  • 1
    Your `if()` doesn't really make sense. Explain what you think it is doing or expect it to do. Also need to confirm you even have access to the frame as you can't access frames from different origin than the page – charlietfl Sep 07 '20 at 16:39
  • @charlietfl im trying to search content inside iframe and if found that specific content it will do something.. I manage to change css with this code (added to the question) but cannot change it to make it lookup for specific content. – Antony Sep 07 '20 at 17:37
  • `if( aEl.innerHTML.indexOf('update') > -1)` would make more sense. Still need to confirm you can access the frame though ( same orgin) – charlietfl Sep 07 '20 at 17:39
  • @charlietfl using the code above no, but using the edit 1 I can change stuff in iframe. – Antony Sep 07 '20 at 17:57

0 Answers0