簡體   English   中英

如何在iframe之外獲取元素

[英]How can I get an element outside an iframe

我有下面的代碼。 myscript.js嵌入在https://example.com/iframe3.html iframe3.html嵌入在homepage.html 我的問題是,如何更改myscript.js以便它將iframe之外的內容抓取。 本質上,我試圖獲取id="name"id="age-i"


myscript.js

    var ifr = document.createElement("iframe");
    var theage = document.getElementById("age-i").innerHTML;
    ifr.src = "https://example.com/get.php?age-i=" + theage;
    ifr.style.visibility = "hidden";
    document.body.appendChild(ifr);

homepage.html

<td width="340" align="right">
  <div id="userarea">
    <div>
      <div id="userarea-line1">
        <a href="#"><img src="/common/img/icons/home.png" width="14" height="14" /></a> <a id="name" href="#"><span class='notranslate'>John</span></a> | <a href="#">Account</a> | <a href="#" style="margin-right:5px;">Smith</a> </div>
      <div id="userarea-line2"> <img width="10" height="11" src="/common/skin/base/icons/icn_age.gif" />&nbsp; <span class="age-format"> <a href="#"><strong id="age-i"><span class='notranslate'>26</span></strong> age</a>
      </span> <img width="10" height="11" align="top" src="/common/skin/base/icons/icn_age.gif" /> <span class="age-format" style="margin-right:5px;"> <span id="month-i"> <span class='notranslate'>03</span> </span> month</span>
      </div>
    </div>
  </div>
</td>
<iframe id="myframe_content" frameborder="0" src="https://example.com/iframe3.html" name="myframe_content"></iframe>

iframe3.html

<script type="text/javascript" src="https://example.com/myscript.js"></script>

我相信現有的stackoverflow帖子: 從另一個iframe訪問一個iframe的元素應該可以回答您的問題。

謝謝,
阿赫亞

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM