zoukankan      html  css  js  c++  java
  • top,self,parent,open,href,location 详细解释

    top,self,parent,open,href,location 详细解释

    关于这几个常用的脚本关键字,很多人经常会很不明白,现在我采用下面的方式相信能很快明白:(如果A,B,C,D,Page都是htm,D是C的iframe,C是B的iframe,B是A的iframe,Page是公共呈现页面。如果D中js这样写)

    大致页面的源码如下:

    D.htm

    <!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <htmlxmlns="http://www.w3.org/1999/xhtml">

    <head>

        <title></title>

     

        <scripttype="text/javascript">

            /*注释部分与非注释部分等价*/

            /*iframe嵌套关系是A->B->C->D*/

            functionfun1() {

                window.open("Page.htm", "_blank");

                // = window.open("");

    <!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <htmlxmlns="http://www.w3.org/1999/xhtml">

    <head>

        <title></title>

    </head>

    <body>

        <h1style="color: Purple; font-size: xx-large; font-weight: bolder;">

            你进入了Page.htm</h1>

    </body>

    </html>

     

            }

            functionfun2() {

                location.href = "Page.htm";

                //= window.location.href = self.location.href = "Page.htm"; //在D页面实现展现

                //=window.open("Page.htm", "_self"); //在D页面实现展现

            }

            functionfun3() {

                parent.location.href = "Page.htm"

                // = window.parent.location.href = "Url地址"; //在C页面实现展现

                //=window.open("Page.htm", "_parent"); //在C页面实现展现

            }

            functionfun4() {

                top.location.href = "Page.htm"

                // = window.top.location.href = "Page.htm"; //在A页面实现展现

                // =window.open("Page.htm", "_top")//在A页面实现展现

            }

            functionfun5() {

                parent.parent.location = "Page.htm"; //在B页面实现展现

                //=parent.open("Page.htm", "_parent") = parent.parent.open("Page.htm", "_self") //在B页面实现展现

            }

           

        </script>

     

    </head>

    <body>

        <h1style="color: Red;">

            D</h1>

        <inputtype="button"id="btn1"value="window.open"onclick="fun1()"/><br/>

        <inputtype="button"id="btn2"value="location.href"onclick="fun2()"/><br/>

        <inputtype="button"id="btn3"value="parent.location.href"onclick="fun3()"/><br/>

        <inputtype="button"id="btn4"value="top.location.href"onclick="fun4()"/><br/>

        <inputtype="button"id="btn5"value="parent.parent.location"onclick="fun5()"/><br/>

    </body>

    </html>

    C.htm

    <!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <htmlxmlns="http://www.w3.org/1999/xhtml">

    <head>

        <title></title>

    </head>

    <body>

        <h1style="color: Yellow;">

            C</h1>

        <iframesrc="D.htm"style="width: 600px; height: 800px"></iframe>

    </body>

    </html>

     

    Page.htm

    <!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <htmlxmlns="http://www.w3.org/1999/xhtml">

    <head>

        <title></title>

    </head>

    <body>

        <h1style="color: Purple; font-size: xx-large; font-weight: bolder;">

            你进入了Page.htm</h1>

    </body>

    </html>

    A.htm 效果如下:


    从上至下一次点击五个按钮效果如下:

    1.

    2.



    3.

    4.

    5.




  • 相关阅读:
    &与&&的区别
    jsp之response方法
    一个数组先按照某个属性的大小排序,如果大小一样的就按照名称排序
    CSS内部div设置上min-height或max-height滚动条就会出现在父元素上
    300行代码手写简单vue.js,彻底弄懂MVVM底层原理
    JavaScript简单手写观察者模式
    javascript中replace还可以这样玩
    VUE中通过改变key去更新局部dom
    element中select的change方法如何传多个参数
    react打包中不想要sourceMap,但是在命令里加'GENERATE_SOURCEMAP=false'后windows下报错'GENERATE_SOURCEMAP' 不是内部或外部命令,也不是可运行的程序 或批处理文件。
  • 原文地址:https://www.cnblogs.com/chenqianpeng/p/2479113.html
Copyright © 2011-2022 走看看