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

보낸 사람 JQ docs.일반적인 방법으로 동일한 도메인의 iframe에 액세스 할 수없는 이유는 무엇입니까?

로컬 호스트에서 문제가 될 수 있습니까?

<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> 

나를 위해 작동하지 않습니다.

+0

이 부모 창 – putvande

+0

@putvande의 도메인 무엇입니까, 모두 메인 페이지 및 iframe을 사용하여 색상을 변경하려고 아직 때 그것은 또한 당신의 iframe을 준비 아니라고 수 있습니다 로컬 호스트 –

+0

에 있습니다. 그것을 setTimeout에서 감싸고 무슨 일이 일어나는지 보거나 iframe에 'onload'를 추가하십시오. – putvande

답변

2

이렇게하려면 onload 이벤트를 iframe에 추가해야합니다. document.ready이 호출 될 때 iframe이 완전히로드되지 않을 수 있습니다.

iframe의 소스가 동일한 도메인에있는 경우에만 작동합니다.

관련 문제