当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


HTML History length用法及代码示例


HTML中的“历史记录长度”属性用于返回当前浏览器窗口的历史记录列表中的URL计数。此属性返回的最小值为1,因为当前当前页面已加载,而最大计数则可以显示为50。Web浏览器(例如Internet Explorer和Opera)的计数从0开始。

用法:

history.length

以下示例程序旨在说明HTML中的History length属性:


例:

<!DOCTYPE html> 
<html> 
    <head>  
        <title>DOM History length Property</title>  
        <style>  
            h1 {  
                color:green;  
            }  
            h2 { 
                font-family:Impact; 
            } 
            body {  
                text-align:center;  
            }  
        </style>  
    </head> 
    <body> 
        <h1>GeeksforGeeks</h1>  
        <h2>DOM History length Property</h2>  
        <p> 
         For displaying the count of URLs in the 
         history, double click the "View URL Count" 
         button:
        </p> 
        <button ondblclick="history_length()"> 
         View URL Count 
        </button> 
        <p id="history"></p> 
        <script> 
            function history_length() { 
                var h = history.length; 
                document.getElementById("history").innerHTML = h; 
            } 
        </script> 
    </body> 
</html>                    

输出:

单击按钮后:

支持的浏览器:下面列出了History length属性支持的浏览器:

  • 谷歌浏览器
  • IE浏览器
  • Firefox
  • Opera
  • Safari


相关用法


注:本文由纯净天空筛选整理自Shubrodeep Banerjee大神的英文原创作品 HTML | DOM History length Property。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。