Search code examples
javascriptdom-events

IFrame Passing value


I have an iframe issue. I have a page where I have a dial. On- click the dial needle show me the value of an angle. Now I want to pass this value of angle from my dial.html page to my parent page on certain location.. I have tried below code. It gives me both dial and angle within the frame. I want to take this angle value and show it in different location. So how would I pull out this angle value from iframe to a different location in my parent page.

<iframe name="clkwise1" id="clkwise1" src="Dial1.htm" width=150 height=215 frameborder=0 scrolling="no" ></iframe>



function myAngle() {

    var iframeVal= document.getElementById('clkwise1').contentWindow;       
    document.getElementById("anglevalue").innerHTML = iframeVal;

   
}

Solution

  • Just access the iframe's document and set a variable there:

    var iframe = document.getElementById('clkwise1').contentWindow;
    iframe.clockAngle = localClockAngle;