html 后台导航 iframe 点击换url

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/a114469/article/details/82186835

写了个小项目,上网随便找了个后台模板 ,又不想重复加载head,footer......

想到了用iframe ....  哈哈哈哈 随便写写.... 随意挑错 .... 欢迎大家指教

id=“nav_menu” 加在了二级菜单的 ul 上........

    <script type="text/javascript">
        //导航
        $('#nav_menu a').click(function(){
            //选中样式
            $(".am-fr").removeClass('am-icon-star');
            $(this).children('.am-fr').addClass('am-icon-star');
            //url
            href = $(this).attr('href');
            $('#iframe').attr('src',href);
            if_title = $(this).children('span').text();
            var iframe = document.getElementById("iframe");
            //iframe加载完,隐藏滚动条,替换内容里title
            iframe.onload = function(){
                hideS();
                document.title = iframe.contentWindow.document.title;
                $("#iframe").contents().find("#if_title").text(if_title);
            } 
            return false;
        });

        /*//iframe是否加载完,并且隐藏滚动条
        var iframe = document.getElementById("iframe");
        if (iframe.attachEvent){
          iframe.attachEvent("onload", function(){
            hideS();

          });
        } else {
          iframe.onload = function(){
            hideS();
            document.title = iframe.contentWindow.document.title;
          };
        }*/

        function hideS()
        {
          document.getElementById("iframe").scrolling="no";
          document.getElementById("iframe").style.overflow="hidden";
        }
    </script> 
<script type="text/javascript">
    //导航
    $('#nav_menu a').click(function(){
        //选中样式
        $(".am-fr").removeClass('am-icon-star');
        $(this).children('.am-fr').addClass('am-icon-star');
        //url
        href = $(this).attr('href');
        $('#iframe').attr('src',href);
        return false;
    });


    //iframe是否加载完,并且隐藏滚动条
    var iframe = document.getElementById("iframe");
    if (iframe.attachEvent){
      iframe.attachEvent("onload", function(){
        hideS();

      });
    } else {
      iframe.onload = function(){
        hideS();
        document.title = iframe.contentWindow.document.title;
      };
    }

    function hideS()
    {
      document.getElementById("iframe").scrolling="no";
      document.getElementById("iframe").style.overflow="hidden";
    }
</script> 

猜你喜欢

转载自blog.csdn.net/a114469/article/details/82186835