zoukankan      html  css  js  c++  java
  • 父页面内获取获取iframe内的变量或者是获取iframe内的值

    前提:页面不可跨域访问,必须同一域名下,否则返回值为空

    父页面

    <!DOCTYPE html>
    <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>Document</title>
        <script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
        <style>
    
        iframe{
                position: absolute;
                top: 0;
                left: 0;
                 100%;
                height:80%;
                bottom: 80%;
            }
            .read{
                position: absolute;
                bottom: 0;
                 100%;
                height: 20%;
            }
    
        </style>
    </head>
    <body>
        <!-- <iframe id="index" name="index" src="http://daogou.qionglegou.com/index.php?r=p/d&id=17331579&source=1l" frameborder="0"></iframe> -->
        <iframe id="index" name="index" src="/content.html" frameborder="0"></iframe>
        <script>
            $(function(){
                var oFrm = document.getElementById('index');
                oFrm.onload = oFrm.onreadystatechange = function () {
                    if (this.readyState && this.readyState != 'complete') {
                        //alert("加载中。。。");
                    }
                    else {
                        var dom =$(window.frames["index"].document).find(".goods_reco").data('datasid');
                        console.log(dom)
                        var c = $('#index')[0].contentWindow;
                        console.log(c.goodsItem.goodsid);
    
                    }
                }
            })
        </script>
    </body>
    </html>

    子页面

    <!DOCTYPE html>
    <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>Document</title>
        <script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
    </head>
    <body>
        <div class="goods_reco" data-datasid='123456'>1111111111</div>
        <script>
            var goodsItem = {goodsid:'123312312'};
        </script>
    </body>
    </html>

  • 相关阅读:
    【转】pymongo实现模糊查询
    使用pip安装包提示TLS证书错误解决办法
    sed用法去除行首和行末的中括号
    logstash之filter处理中括号包围的内容
    根据IP查地理位置信息
    shell生成连续天数日期
    linux grep 取出特定字符串并统计个数
    【转】css3实现文字闪烁,改变透明度
    【转】Django中使用POST方法获取POST数据
    [算法]机器人运动范围
  • 原文地址:https://www.cnblogs.com/NB-JDzhou/p/10019090.html
Copyright © 2011-2022 走看看