0

if I have the "src" attributes in IFRAME change is the "onload" Function not executed. It works ONLY when first called.

JavaScript:

function dialog () {
    document.getElementById('result').src = "myurl";
}

function loading() {
    document.getElementById('loading').style.display = "none";
    document.getElementById('result').style.display = "block";
}

HTML:

<div id="loading"><img src="loading.gif"/></div>
<iframe style="display:none;" id="result" onload="loading();" src="myurl"/></iframe>

Thank you!

Fabian N.
  • 3,807
  • 2
  • 23
  • 46
od_
  • 183
  • 3
  • 16

1 Answers1

0

Does your page domain and iframe domain the same? If they are different you can use CORS to access iframe events.


EDIT

<script>

    function dialog() {
        document.getElementById('result').src = "http://jsfiddle.net";
    }
    function loading() {
        alert('Loading finished');
        document.getElementById('loading').style.display = "none";
        document.getElementById('result').style.display = "block";
    }

</script>

<div id="loading">Loading</div>
<iframe  style="display:none;" id="result" onload="loading();" src="http://jsfiddle.net"/>

It works, live demo -- http://jsfiddle.net/xf2LgLsg/ I believe you write JS after HTML, so this may be a problem.

MaximOrlovsky
  • 265
  • 2
  • 8