Reputation: 151
So I have an iframe from an external domain on my webpage. Inside that iframe there is a <span>
element that have some text in it.
Is there any way I can get the content of that <span>
element. I would like to get the text or ideally the class of that element.
I was trying to do that using JQuery with this code:
var fbIframe = $("#arvlbdata").find("iframe");
var likeBar = fbIframe.contents().find("$u_0_4");
if (($("#arvlbdata").find("iframe").find("#u_0_4").attr("class")) =="hidden_elem" )
alert("test");
Of course, it didn't work because of the same origin policy.
Is there any way I can do this?
What I was trying to achieve is tell if the user has already liked the page and not displaying my pop up box with FB plugin to those users, without loggin users into my app and asking for users permission.
Upvotes: 0
Views: 164
Reputation: 40814
No, unless it's on the same origin, there's no way to do this.
The reasoning is that if you can access an external webpage from another origin inside an iframe, then you could for instance access a user's sensitive details on the other site if they're logged in (e.g., on a bank's website, you could embed that in an iframe). Thus browsers won't allow you to read the contents of an iframe from a different origin.
Upvotes: 2