• 跨域 (3) window.name


    window对象有一个name属性,该属性有一个特征:即在一个窗口的生命周期内,窗口载入的所有的页面都是共享一个window.name的,每一个页面对window.name都有读写的权限,window.name是持久的存在于一个窗口载入的所有页面中的,并不会因为新的页面的载入而被重置。

    a.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>a  页面 </title>
    </head>
    <body>
         <!-- a先引用 c -->
        <iframe src="http://localhost:4000/c.html" frameborder="0"  onload="load()"  id="iframe"></iframe>
    </body>
    <script>
      let  first  = true;
      function load() {
          if(first) {
                 //把 a 引用的地址改到b
                    let  iframe =  document.getElementById('iframe')
                    iframe.src= 'http://localhost:3000/b.html'
                    first  = false
          }else {
              console.log(iframe.contentWindow.name)
          }
      }
    </script>
    </html>

    c.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>
    </head>
    <body>
        
    </body>
    <script>
        //   c页面把值放到window 下
       window.name ='hello world'
    </script>
    </html>

    注释:

    a 和 b 是同域名的 http://localhost:3000

    c 是独立的 http://localhost:4000

    a先获取c 的数据

    a先引用 c c把值放到window.name ,把 a 引用的地址改到b

  • 相关阅读:
    七。进度管理
    六。质量管理
    五。项目范围管理
    四。项目整体管理
    三。项目立项管理
    二。项目的一般只知识
    一。项目管理的管理领域
    8.BGP
    英语词汇基础
    vim中输入tab符
  • 原文地址:https://www.cnblogs.com/guangzhou11/p/11619363.html
Copyright © 2020-2023  润新知