0

I have elements on my parent page that changes only if hidden iframe within contain one div id.

Everything is fine if I let code on html page :

 <iframe id="myiframe" style="display:none" onload="load()" name="myiframe"   src="mysite.com"></iframe>

JavaScript:

function load(){


if (window.frames[0].document.getElementById('applications'))
{
var str=document.getElementById("tst").innerHTML;
var n=str.replace("Login","Logout");}}
document.getElementById('tst').href='logout';

But I need iframe code deleted from html file and relocated js file.

I use this code in js file to trigger iframe:

window.onload = function(){
var link = "iframelink"
 var iframe = document.createElement('iframe');
iframe.frameBorder=0;
iframe.width="300px";
iframe.height="250px";
iframe.id="randomid";
iframe.addEventListener("load", load);
iframe.setAttribute("src", link);
document.getElementById("ad54").appendChild(iframe);
}

html code to get iframe:

<div id="ad54"</div>

Iframe launches, but right now I get no elements changed on parent page although iframe is triggered . When iframe is loaded I need those changes to take place in parent page.

4
  • Are both pages (parent and iframe) on the same domain? Commented Mar 18, 2013 at 14:08
  • Yes , on the same domain. Iframe closed :) Commented Mar 18, 2013 at 14:15
  • Im a little confused with what you are trying to achieve. You have load() called twice, once for the iframe and also for the div (which isnt supported by the way) Commented Mar 18, 2013 at 14:21
  • If div id 'applications' is found on iframe within parent page, then we change 'Login' in 'Logout' on parent page. I remove it onload="load()" from div, added iframe.addEventListener("load", load) on js file; but still no changes. Commented Mar 18, 2013 at 14:31

1 Answer 1

1

<div> elements do not load external content, so they never fire load events.

You appear to be trying to fire the event when the iframe content loads. You need to attach your event listener to the iframe.

iframe.addEventListener("load", load);
iframe.setAttribute("src", link);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.