[HTML5] 隱藏首頁
有時候要隱藏首頁是件麻煩事,有三種方法可以來解決此事
首先要設定style區塊將iframe填滿Browser
<style>
html,body { height: 100%;padding:0px;margin:0px; }
.stockIframe { width:100%; height:100%; }
.stockIframe iframe { width:100%; height:100%; border:0;overflow:hidden }
</style>
三種不同的Java Script
1.
//onload="autoResize(this)"
function autoResize(i) {
var iframeHeight=
//(i).contentWindow.document.body.scrollHeight;
(i).contentDocument.documentElement.scrollHeigh;
(i).height=iframeHeight+20;
};
2.
//onload=SetCwinHeight()
function SetCwinHeight(){
var iframeid=document.getElementById("mainframe"); //iframe id
if (document.getElementById){
if (iframeid && !window.opera) {
if (iframeid.contentDocument && iframeid.contentDocument.body.offsetHeight) {
iframeid.height = iframeid.contentDocument.body.offsetHeight;
}
else if(iframeid.Document && iframeid.Document.body.scrollHeight) {
iframeid.height = iframeid.Document.body.scrollHeight;
}
}
}
};
3.
//onload=dyniframesize(iframename)
function whichBrs() {
var agt = navigator.userAgent.toLowerCase();
if (agt.indexOf("opera") != -1) return 'Opera';
if (agt.indexOf("staroffice") != -1) return 'Star Office';
if (agt.indexOf("beonex") != -1) return 'Beonex';
if (agt.indexOf("chimera") != -1) return 'Chimera';
if (agt.indexOf("netpositive") != -1) return 'NetPositive';
if (agt.indexOf("phoenix") != -1) return 'Phoenix';
if (agt.indexOf("firefox") != -1) return 'Firefox';
if (agt.indexOf("safari") != -1) return 'Safari';
if (agt.indexOf("skipstone") != -1) return 'SkipStone';
if (agt.indexOf("msie") != -1) return 'Internet Explorer';
if (agt.indexOf("netscape") != -1) return 'Netscape';
if (agt.indexOf("mozilla/5.0") != -1) return 'Mozilla';
if (agt.indexOf('\/') != -1) {
if (agt.substr(0, agt.indexOf('\/')) != 'mozilla') {
return navigator.userAgent.substr(0, agt.indexOf('\/'));
}
else return 'Netscape';
} else if (agt.indexOf(' ') != -1)
return navigator.userAgent.substr(0, agt.indexOf(' '));
else return navigator.userAgent;
};
function dyniframesize(iframename) {
var iframe = null;
if (document.getElementById) {
iframe = document.getElementById(iframename);
}
else {
eval('iframe = ' + iframename + ';');
}
//begin resizing iframe
iframe.style.display = "block"
if (iframe.Document) {//ie
//iframe.height = iframe.contentDocument.body.scrollHeight;
iframe.height = iframe.Document.body.scrollHeight;
} else if (iframe.contentDocument) {//ie,firefox,chrome,opera,safari
if (whichBrs() == "Firefox") {
iframe.height = iframe.contentDocument.documentElement.offsetHeight;
}
else { //safari
iframe.height = iframe.contentDocument.documentElement.scrollHeight;
}
}
};
沒有留言:
張貼留言