当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - Change innerHtml From Iframe

问题描述:

I'm attempting to change the innerHTML of a div from the ready function of an iframe's src. Code below. The innerHtml will not change, but the color works fine. Ideas on why this is happening and/or how to fix it?

Page

<html><head></head><body>

<script type="text/javascript" src="Javascript/Import_Subprocess_Content/RAC_Connolly.js"></script>

<div id="importcontent" runat="server">

</div>

<iframe id="frametest" src="./AJAX/Import_Subprocess_Content/RAC_Connolly_ImportSession.aspx">

</iframe>

<div id="popup">FIRST TEXT</div>

</body>

Iframe src

<script type="text/javascript" src="../../Utilities/Javascript/jquery-1.7.1.min.js"></script>

<script type="text/javascript" src="../../Javascript/Import_Subprocess_Content/RAC_Connolly.js"></script>

<script type="text/javascript">

$(document).ready(function () {

uploadComplete();

});

</script>

end it!

js

function uploadComplete() {

window.parent.document.getElementById("popup").innerHtml = "lala";

}

Testing in IE7 exclusively.

网友答案:

A workaround you can try:

  1. Transfer uploadComplete method to parent.

    function uploadComplete() {
       document.getElementById("popup").innerHtml = "lala";
       return false;
    }
    
  2. Call this method in your iFrame

    <script type="text/javascript">
    $(document).ready(function () {
        parent.uploadComplete();
    });
    </script>
    

Similar question: Iframe Function Calling From Iframe to parent page javascript function

网友答案:

Capitalization issue. Correct syntax is

document.getElementById("ID").innerHTML = "HTML";

not

document.getElementByID("ID").innerHtml = "HTML";

I was following a fusion of c# and javascript maybe with a VB twist syntax due to switching languages so often. Stupid small errors, big problems.

分享给朋友:
您可能感兴趣的文章:
随机阅读: