2

I have found multiple posts on how to add css to iframe content and this is my code:

$(function() {
    $('iframe').addClass('bro'); //does work
    $('iframe').contents().find('html').addClass('broz'); //doesn't work
    $('iframe').contents().find('.side-section').addClass('brozzz'); //doesn't work
});

The first one works, as expected, but then all the other identifiers don't work. I am just trying to test out why they aren't working, this isn't the actual work I'm doing.

This is the iframe code:

<iframe src="http://www.dropcards.com/download/profilewidget/?ArtistID=17121" width="400" height="230" scrolling="no" frameborder="0" allowtransparency="true" ></iframe>
1
  • using latest jquery if that matters Commented Jul 14, 2012 at 22:03

2 Answers 2

4

You cannot modify the dom of the page in an iframe, if the page is not from the same domain as the domain containing the iframe. The idea is to to prevent XSS, cross-side-scripting.

You can find more info heresame origin policy

In the first case, you are modifying your page's dom, in the next 2 cases, this is not possible since, you do not have access to the dom of the page contained in the iframe

Sign up to request clarification or add additional context in comments.

1 Comment

ok thanks for the info! It is interesting that all the questions about how to do this never mention if it is from the same domain or not, but I do see why this feature is there: stackoverflow.com/questions/3714880/…
1

if the the contents of the iframe are from another domain you are not allowed to manipulate them.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.