Joe Half Face
Joe Half Face

Reputation: 2333

Why I can't access iframe on same domain with common approach?

<script>
$( "#frameDemo" ).contents().find( "a" ).css( "background-color", "#BADA55" );
</script>

From JQ docs.

May be problem is that I do it on localhost?

  <script>
    $(document).ready(function(){

      $('#sample_test').contents().find('a').css('color', 'red')
    })

</script>
<iframe src="http://localhost:3000/tests/384"  width="100%" seamless="seamless"  height="1150px" scrolling="no" id="sample_test"></iframe>

Doesn't work for me for some reason.

Upvotes: 2

Views: 781

Answers (1)

putvande
putvande

Reputation: 15213

You have to add an onload event to the iframe in order to do that. The iframe might nog be fully loaded yet when the document.ready is called.

But this will only work if the source in the iframe is from the same domain.

Upvotes: 2

Related Questions