• 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.




  • 相关阅读:
    C#零相位数字滤波器,改写自Matlab函数filtfilt
    [收藏]C语言格式化字符串
    C#调用PMAC运动控制卡的pcomm32动态链接库的数据类型转换
    [收藏]常见逻辑电平标准
    主要软件作品展示
    新一年希望做的事情
    单元测试的思维导图
    SQLite简单教程
    关于动态执行SQL Statement on ISeries
    突然发现一个 IBM.Data.DB2.ISeries的一个小问题,也是很头痛的问题
  • 原文地址:https://www.cnblogs.com/chenqianpeng/p/2479113.html
Copyright © 2020-2023  润新知