html 後臺導航 iframe 點選換url
阿新 • • 發佈:2018-12-25
寫了個小專案,上網隨便找了個後臺模板 ,又不想重複載入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>