JavaScript-将当前窗口设置为顶级窗口-内嵌窗口ifname

 1、内嵌窗口:<iframe src="005.html"width="500px" heigth="500px"></iframe>

 2、如果当前这个窗口不是顶级窗口的话,将当前窗口设置为顶级窗口:记住下面一行代码:

if(window.top!=window.self){
      window.top.location=window.self.location;
}
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>004将当前窗口设置为顶级窗口</title>
    </head>
    <body>
        <iframe src="005.html"width="500px" heigth="500px"></iframe>
    </body>
</html>

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>005页面</title>
        <!--
        004--005联合起来看代码,005和这个知识点一样
        如果当前这个窗口不是顶级窗口的话,将当前窗口设置为顶级窗口
        if(window.top!=window.self){
              //将当前窗口设置为顶级窗口
             window.top.location=window.self.location;
        }
        iframe 引进页面.内嵌框架<iframe src="005.html"width="500px" heigth="500px"></iframe>
        -->
    </head>
    <body>
        005页面
        <script type="text/javascript">
            /*如果当前这个窗口不是顶级窗口的话,将当前窗口设置为顶级窗口*/
           function setTop(){
               if(window.top != window.self){
                  //将当前窗口设置为顶级窗口
                  window.top.location=window.self.location;
                }
           }
        </script>
        <input type="button" onclick="setTop()" value="如果当前这个窗口不是顶级窗口的话,将当前窗口设置为顶级窗口"/>
        
    </body>
</html>
运行效果:

 

posted @ 2022-06-12 21:04  280887072  阅读(334)  评论(0)    收藏  举报