DIV CSS 佈局教程網

JS去除iframe捲軸的方法
編輯:關於JavaScript     

本文示範如何透過修改 scrolling 屬性來隱藏 iframe 的捲軸。

把 scrolling 設為 "no" 即可關閉捲軸,設為 "auto" 則是內容超出時才出現。

 <!DOCTYPE html> <html> <head> <script> function removeScroll() { document.getElementById("myframe").scrolling="no"; } </script> </head> <body> <iframe id="myframe" src="/default.asp" scrolling="auto"> <p>Your browser does not support iframes.</p> </iframe> <p>The value of the scrolling attribute is: <script> document.write(document.getElementById("myframe").scrolling); </script> <p> <input type="button" onclick="removeScroll()" value="Remove Scrollbars"> <p>Internet Explorer, Google Chrome, Opera, and Safari have problems with setting the scrolling attribute.</p> </body> </html>

如範例最後一段所述,IE、Chrome、Opera 與 Safari 在動態設定 scrolling 屬性時都有相容性問題——這個屬性在很多瀏覽器中已被視為唯讀或直接被忽略。較可靠的做法是改在 iframe 的 CSS 上動手腳,例如對 iframe 套用 scrolling="no" 的 HTML 屬性(寫在標籤上而非用 JS 改),或在內層文件用 body { overflow: hidden } 控制。

希望本文所述對大家的 JavaScript 程式設計有所幫助。

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved