user2619234
user2619234

Reputation: 13

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>

Upvotes: 1

Views: 7273

Answers (3)

Neeraj
Neeraj

Reputation: 4489

Try this but make sure Iframe and your origin page in same domain as iframe does not support cross domain

JavaScript

window.parent.document.getElementById('parentElement')[0].innerHTML;;

Jquery

 $('#parentElement', window.parent.document);

Upvotes: 1

adeneo
adeneo

Reputation: 318252

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

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

Upvotes: 1

gezzuzz
gezzuzz

Reputation: 178

this is for outside the iframe trying to see whats inside..

document.getElementById("myiframe").contentWindow.document.getElementById()

but you have to be on the same domain

Upvotes: 0

Related Questions