-1

I want to write a script to watch online courses automatically using Javascript. But when I want to locate an element in the html page,I find it was in an embedded web page which also in an embedded web page. I have been searching questions in Google and Baidu but I only find the way how to locate an element in an embedded web page. I also ask programmers around me but they also have no idea,oops. the following picture is the position of it("span" is the target).

<html>
  <body>
    <div class="main">
      <iframe id="iframe" src="blala" allowfullscreen="ture" onload="clickImg()">
        <html>
          <body>
            <div class="ans-job-icon"> 
               <iframe src="video/blala" allowfullscreen="ture">
                   <html>
                     <body>
                         <span aria-hidden="true" class="vjs-icon-placeholder"></span>
                     </body>
                   </html>
               </iframe>
          </body>
        </html>
      </iframe>
  </body>
</html>

Can you do me a favor? thx a lot.

1 Answers1

0

Thank for all of your idea. With your advice, I finally work out this question with my friends. The solution is as followed.
We find that “window" is one of the object in JavaScript, which can operate the element in "iframe". So you can use it to locate the tag in an embedded web page.

  1. top

    "top" is an attribute in the object window. By using the statement "window.top", you can get the top window in the web page. and then

  2. Using the statement"window.top.iframe" to get the iframe object .

  3. get the next iframe tag by object "document" attribute "contentDocument" in iframe can be used to return the current document object. and then you can find the next iframe using the statement"window.top.iframe.contentDocument.getElementsByTagName('iframe')[0]"!

Community
  • 1
  • 1