美文网首页
iframe嵌套localStorage获取

iframe嵌套localStorage获取

作者: diviner_杨 | 来源:发表于2020-04-27 11:22 被阅读0次

    父页面 parentPage.html

    <!doctype html>
    <html lang="zh">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport"
              content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Document</title>
        <style>
             * {
                padding: 0;
                margin: 0;
            }
    
            html, body {
                height: 100%;
                width: 100%;
                overflow: hidden;
            }
    
            iframe {
                border: 0;
            }
            .iframe-class{
                border: 1px solid #000000;
            }
            
        </style>
    </head>
    <body>
    <div id="app">
        <a href="#" @click="handleCilck">子页面跳转</a>
        <div class="iframe-class">
            <iframe id="mainContent" width="100%" height="100%"></iframe>
        </div>
        
    </div>
    <script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
    <script>
        new Vue({
            el: '#app',
            data: {
               
            },
            mounted() {
                localStorage.setItem('parentPage', '小提莫');
            },
            methods: {
                handleCilck(){
                    var mainContent = document.getElementById('mainContent');
                    mainContent.src = "./Subpage.html"//嵌套网址
                }
            }
        })
    </script>
    </body>
    </html>
    

    子页面获取Subpage.html

    <!doctype html>
    <html lang="zh">
    
    <head>
        <meta charset="UTF-8">
        <meta name="viewport"
            content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Document</title>
        <style>
    
        </style>
    </head>
    
    <body>
        <div id="app">
            <h2>这是Subpage的界面</h2>
            <a href="#" @click="handleCilck">获取父页面的localStorage</a>
        </div>
        <script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
        <script>
            new Vue({
                el: '#app',
                data: {
                    arrayTwo: []
                },
                methods: {
                    //获取父页面的localStorage信息
                    handleCilck(){
                        let parentPage= localStorage.getItem('parentPage');
                        console.log(parentPage) //小提莫
                    }
                }
            })
        </script>
    </body>
    
    </html>
    

    相关文章

      网友评论

          本文标题:iframe嵌套localStorage获取

          本文链接:https://www.haomeiwen.com/subject/lpcywhtx.html