0

I want to display a rotating banner using html and js. It works locally using a rotating function and window.onload event. For production it actually needs to run in an iframe. The iframe is on the parent page - same domain.

Below is the JS that worked which I'm adapting to make it work. It doesn't display at all. I tried this also. Not good with inspecting elements on the browser yet, but did notice the following error message: 'Uncaught TypeError: Cannot set property 'onload' of undefined'. This message is with regards to document.getElementsByTagName('iframe')[0].onload = rotater; below in JS:

function rotater() {
    document.getElementById("placeholderdiv").innerHTML = items[current];

    current = (current === items.length - 1) ? 0 : current + 1; //increment or reset
    setTimeout("rotater()", howOften);
}

document.getElementsByTagName('iframe')[0].onload = rotater;

iFrame code:

<iframe id="id_gateway_120" title="My Workspace Information Message" style="width:100%;padding:0 !important; 
height:600px" marginwidth="0" marginheight="0" scrolling="auto" 
src="/access/content/public/site/pages/homev1.html" width="100%" frameborder="0">
Community
  • 1
  • 1
louisav
  • 372
  • 1
  • 5
  • 26

1 Answers1

0

Not sure what you are trying to do in context, but did you try this? document.getElementsByTagName('iframe')[0].onload = rotater;

sam
  • 30
  • 2
  • yes, tried that - no difference. Edited question: the iframe is on a parent page of the same domain. – louisav Oct 08 '16 at 18:42
  • document.getElementById("placeholderdiv").innerHTML = items[current];} change to document.getElementById("placeholderdiv").innerHTML = items[current]; and see if that helps... – sam Oct 08 '16 at 20:23
  • sorry, that's a typo in my question. Not in the code. The problem lies with `document.getElementsByTagName('iframe')[0].onload = rotater;` seems it's not seeing the iframe. – louisav Oct 08 '16 at 21:33
  • not done
    My modified version works just fine for me. Are you sure, you have the iframe in the document before you reference it in code?
    – sam Oct 10 '16 at 14:17
  • Updated question with the iframe. My other code is in homev1.html which follows after the iframe. Remember my iframe is in a parent document though, it's not the same html file. – louisav Oct 10 '16 at 19:48
  • I do not even know what line 73 is. If line 73 is “document.getElementsByTagName('iframe')[0].onload = rotater;” then you’re trying to access the iframe that is not loaded in the DOM. Move the iframe above the code. Otherwise, I would have to see the whole code to see where the problem is. The content of the iframe should not play any part. – sam Oct 10 '16 at 20:01
  • I'll have to get the code to you then. iframe definitely above the code, since my html content is displaying inside the iframe. The src value of the iframe is my html file. – louisav Oct 10 '16 at 20:11