Accessing id from iframe

Here I have created an HTML page with iFrame

. I had an id in iFrame

src page . Is it possible to access the id from my current page using JavaScript.

Please help me.

+1


source to share


2 answers


You have to be careful if you are accessing the iframe script from your parent page to ensure that your iframe has finished loading before requesting it. Here's an example:



window.onload = function () {
    document.getElementById('iframeId').onload = function () { //Attach an onload function to the iframe
        //Do the stuff you want to do with the iframe here
        //because this function is executed once the iframe has finished loading
    };
};

      

+1


source


This is a small example I followed,

<title>Untitled Page</title>
<script type="text/javascript" >
    function ShowVal() {
        alert(myIframe.document.getElementById('nameText').value);
    }

</script>

      

'myIfrmae' is the id of the iframe. and 'nameText' is the textbox control on the page contained in the iframe.



I was calling this ShowVal function from the parent page with a single button click.

Thank.

PS Sorry, failed to post the whole example. Having problems publishing Html.

0


source







All Articles