marius
marius

Reputation: 329

refresh iframe parent page using getElementById

Is is possible to refresh only once iframe parent page when iframe contain specified div id ?

I tried this on parent page but didn't work :

if document.frames('myiframe').(document.getElementById("iframedivID") !== null) { window.location.href = "mysite.com"; } 

Upvotes: 2

Views: 310

Answers (1)

Ravindra Gullapalli
Ravindra Gullapalli

Reputation: 9188

It is taking time to load the inner document. So we have to wait till inner document gets loaded and once it is loaded, the inner div can be accessed. Here is my example HTML and javascript code. Due to this, for the first time, you may get null in the alert. Hope this helps.

Test.html

<iframe id="iframedivID" src="Test1.html"></iframe>

Test1.html

<div id='myDiv'>My name is ravindra</div>
<script type="text/javascript">
    if (window.parent.window.location.href.toString().indexOf("?refresh") == -1){
        window.parent.window.location.href="Test.html?refresh";
    }
</script>

Upvotes: 2

Related Questions