Search code examples
javascriptasp.net.netiframeparent

how to get a class value from an iframe parent page


I have two applications one is already built and the other one is my own I can't do any modification in the first one and it uses iframes and in that frame I can put my application but I will need the name of the connected users which the only option is to get it from the source code using javascript the problem is that user name inside a css class not id if you have any ideas how can I get it please help thanks to you all

            <div class="Entete_User">
            <div class="Entete_UserName">USER NAME <br> USER CITY</div>
    </div>
    <div class="body">
        <iframe id="myiframe" frameborder="0" allowTransparency="allowTransparency" src="MYPAGE.aspx"></iframe>
    </div>
</form>


Solution

  • To get the content of the element in the parent window from inside the iFrame :

    window.parent.document.getElementsByClassName('Entete_UserName')[0].innerHTML;