iframe同域访问

版权声明:多总结,帮助自己的同时也在帮助别人!留下意见和看法,让技术动起来! https://blog.csdn.net/qiphon3650/article/details/87259996
<html lang="en"><head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>iframe test</title>
    <style>
        iframe {
            width: 100%;
            height: 400px;
        }
    </style>
    <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
</head>

<body>
    <div id="aa">
        <iframe id="myframe" src="https://www.digitalin.com.cn/resinfin/#/index?app_id=dinwxpa&amp;loginFlag=mobile" frameborder="0"></iframe>
        <iframe id="myframe1" src="./2.html" frameborder="0"></iframe>
    </div>
    <script>
        $(function () {


            var iframe = document.getElementById('myframe');
            // console.log($("#myframe")[0].contentWindow)
            // console.log(2222222222222,iframe.contentWindow)

            let iframeW = iframe.contentWindow;
            iframe.onload = function () {
                iframe.onclick= function(){
                    console.log(iframeW.document)    // 获取子页面dom
                    console.log($(iframeW.document).find('input'))
                    alert($(iframeW.document).find('.phone input').val())
                    // $(iframeW.document).find('.phone input').on('input',function(ev){
                    //     alert($(this).val())
                    // })
                }
                // console.dir(iframe)
            }
        });

        function hideZKZ() {

            console.log(11111)
        }
    </script>


</body></html>

没有更多推荐了,返回首页