HTML Window length 屬性


HTML Window length 屬性返回當前 HTML 文件中 <iframe> 元素的數量。

語法

語法如下 −

window.length

讓我們看一個 HTML Window length 屬性的示例 −

示例

 檢視演示

<!DOCTYPE html>
<html>
<style>
   body {
      color: #000;
      height: 100vh;
      background-color: #8BC6EC;
      background-image: linear-gradient(135deg, #8BC6EC 0%, #9599E2 100%);
      text-align: center;
   }
   .btn {
      background: #db133a;
      border: none;
      height: 2rem;
      border-radius: 2px;
      width: 40%;
      display: block;
      color: #fff;
      outline: none;
      cursor: pointer;
      margin: 1rem auto;
   }
</style>
<body>
<h1>HTML Window length Property</h1>
<iframe src="https://tutorialspoint.tw/"></iframe>
<button onclick="display()" class="btn">Show the number of iframe</button>
<div class="show"></div>
<script>
   function display() {
      document.querySelector('.show').innerHTML = 'Number of iframe is: ' + window.length;
   }
</script>
</body>
</html>

輸出

點選“顯示 iframe 的數量”按鈕以顯示 HTML 文件中 iframe 的數量 −

更新於: 2019 年 10 月 1 日

125 次瀏覽

開啟您的 職業生涯

透過完成課程獲得認證

開始學習
廣告
© . All rights reserved.