iframe的使用,头部标签切换,不是跳转到新的界面,而是头部保存不变,iframe内容发生变化


header.jsp

<%@page pageEncoding="UTF-8" %>




  
  
  
  公共顶部
  
  
  



  
class="header">
class="header-wrap">
class="footer"> CopyRight(?)2022 All Rights Reserved 版权所有:
global.js
window.onload = function () {
    onloadHeight()
}
$(document).ready(function () {
    $(".header-wrap-list li").click(function () {
        $(this).addClass("tab-nav");
        $(this).siblings().removeClass("tab-nav");
        var itemId = $(this).index();
        var iframe = document.getElementById('frame')
        if (itemId === 0){
            iframe.src = "/kms/newpage/pages/index/index.jsp"
            console.log(0);
            console.log(iframe.src);
            onloadHeight()
        } else if (itemId === 1) {
            console.log(1);
            iframe.src = "/newpage/getDepCategory.do"
            onloadHeight()
        } else if (itemId === 2) {
            console.log(2);
            iframe.src = "/kms/zone/getMyCenter.do"
            onloadHeight()
        } else {
            console.log(3);
            onloadHeight()
        }
    })
})
function onloadHeight() {
    var ifm = document.getElementById("frame");
    var subWeb = document.frames ? document.frames["frame"].document : ifm.contentDocument;
    // console.log(subWeb);
    if (ifm != null && subWeb != null) {
        //清除上一个子页面高度的影响
        $("#frame").height(0);
        $("#frame").height(subWeb.body.scrollHeight);
    }
}