복붙노트

[JQUERY] iframe과 부모 사이의 jquery 변수를 전달하십시오

JQUERY

iframe과 부모 사이의 jquery 변수를 전달하십시오

해결법


  1. 1.

    $("#myid", top.document); 
    

    또는

    $("#myid", parent.document.body); 
    

    이렇게하면 iframe의 컨테이너에 액세스 할 수 있습니다.

    다음과 같이 : http://groups.google.com/group/jquery-en/browse_thread/thread/5997ef4a60a123af.


  2. 2.부모의 관점에서 :

    부모의 관점에서 :

    var iFrameValue = $('#iframe').get(0).contentWindow.myLocalFunction();
    

    또는

    var iFrameValue = $('#iframe').get(0).contentWindow.myLocalVariable;
    

    iframe 관점에서

    <script type="text/javascript">
    
    var myLocalVariable = "hello";
    
    function myLocalFunction () {
        return "hello";
    }
    
    </script>
    

  3. 3.ContentWindow 및 Content Document Properties를 사용하여 동일한 원본 정책이 문제가되지 않습니다. 데모를 설정했습니다. iframe의 데모 및 코드의 코드를 봅니다.

    ContentWindow 및 Content Document Properties를 사용하여 동일한 원본 정책이 문제가되지 않습니다. 데모를 설정했습니다. iframe의 데모 및 코드의 코드를 봅니다.

  4. from https://stackoverflow.com/questions/4689145/pass-jquery-variables-between-iframe-and-parent by cc-by-sa and MIT license