frameset过时,以及用div+iframe的代替frameset实现

今天在学习 java web项目时,书中示例使用了 <frameset></frameset>标签,编译器添加删除线标识该标签过时,最初考虑不影响使用,就没有关心,运行工程后发现网页没有输出,于是查询相关资料,学习记录。

过时的frameset

  • 使用frameset页面空白问题

    这是因为我将 <frameset></frameset> 标签放到了 <body></body> 标签中实现,而<frameset><body>不能一起使用。

  • 在 HTML 5 中不支持 <frameset></frameset> 标签。

  • 使用<frameset>可能会带来session丢失等问题

<frameset id="frame" frameborder="0" framespacing="0"
              rows="100,*" border="false" scrolling="yes">

       <frame name="topframe" scrolling="auto" marginheight="0" marginwidth="0"
              src="header.jsp" noresize>
       <frameset  framespacing="0" border="false" cols="200,*" frameborder=
               "0" scrolling="yes">
           <frame name="leftFrame" scrolling="no" marginheight="0" marginwidth="0"
                  src="index.jsp" noresize>
           <frame name="rightFrame" scrolling="auto"  src="rightFrame.jsp"marginheight="0" marginwidth="0"
           >
       </frameset>
</frameset>

div+iframe替代frameset实现

<html>
<head>
    <title>网上书店</title>

    <style>
        body
        {
            margin: 0;
            padding: 0;
            border: 0;
            overflow: hidden;
            height: 100%;
            max-height: 100%;
        }

        #frameTop
        {
            position: absolute;
            top: 0;
            left: 0;
            height: 100px;
            width: 100%;
            overflow: hidden;
            vertical-align: middle;
        }

        #frameContentLeft
        {
            position: fixed;
            top: 100px;
            left: 0;
            height: 100%;
            width: 150px;
            overflow: hidden;
            vertical-align: top;
            background-color: #D2E6FA;
        }

        #frameContentRight
        {
            position: absolute;
            left: 150px;
            top: 100px;
            height: 100%;
            width: 100%;
            right: 0;
            bottom: 0;
            overflow: hidden;
            background: #fff;
        }
    </style>
</head>
    <%--<frameset id="frame" frameborder="0" framespacing="0"--%>
              <%--rows="100,*" border="false" scrolling="yes">--%>

        <%--<frame name="topframe" scrolling="auto" marginheight="0" marginwidth="0"--%>
               <%--src="header.jsp" noresize>--%>
        <%--<frameset  framespacing="0" border="false" cols="200,*" frameborder=--%>
                <%--"0" scrolling="yes">--%>
            <%--<frame name="leftFrame" scrolling="no" marginheight="0" marginwidth="0"--%>
                   <%--src="index.jsp" noresize>--%>
            <%--<frame name="rightFrame" scrolling="auto"  src="rightFrame.jsp"marginheight="0" marginwidth="0"--%>
            <%-->--%>
        <%--</frameset>--%>
    <%--</frameset>--%>

<body>

    <div>
        <iframe id="frameTop" src="header.jsp"></iframe>
    </div>

    <div>
        <iframe id="frameContentLeft" src="index.jsp"></iframe>
        <iframe id="frameContentRight" src="rightFrame.jsp"></iframe>
    </div>

</body>
</html>

页面效果图

参考

祭奠那过时的框架标签frameset

用div+iframe 代替frameset 框架

Iframe 有什么好处,有什么坏处?国内还有哪些知名网站仍用Iframe,为什么?有哪些原来用的现在抛弃了?又是为什么?



作者:木子礼记
链接:https://www.jianshu.com/p/8c30bb552eca
來源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

来源:https://www.jianshu.com/p/8c30bb552eca

猜你喜欢

转载自blog.csdn.net/qq_42058441/article/details/86564920