用 document.readyState == “complete” 判斷頁面是否載入完成

來源:互聯網
上載者:User
 

轉自:http://www.cnblogs.com/lhb25/archive/2009/07/30/1535420.html

傳回XML 檔案資料的目前狀況。  
基本文法
intState = xmlDocument.readyState; 

說 明

這個屬性是唯讀,傳回值有以下的可能:

0-UNINITIALIZED:XML 對象被產生,但沒有任何檔案被載入。
1-LOADING:載入程式進行中,但檔案尚未開始解析。
2-LOADED:部分的檔案已經載入且進行解析,但物件模型尚未生效。
3-INTERACTIVE:僅對已載入的部分檔案有效,在此情況下,物件模型是有效但唯讀。
4-COMPLETED:檔案已完全載入,代表載入成功。
 
範 例
alert("The readyState property is " + xmlDoc.readyState);  根據頁面載入是否結束來控製圖片大小
<script language="javascript">

if (document.readyState=="complete")
{
        AdjustImageSize();
}
else
{
        document.onreadystatechange = function()
        {
           
                if (document.readyState == "complete")
                {
                        AdjustImageSize();
                }
        }
}

function AdjustImageSize()
{
        var imageWidth = document.all["SendPic"].width;
        var imageHeight = document.all["SendPic"].height;
        
        if (imageWidth == 0 && imageHeight == 0)
        {
                document.write ("圖片下載失敗,請重新整理!");
                return;
        }
        
        if (imageWidth > 160 || imageHeight > 160)
        {
                if (imageWidth > imageHeight)
                {
                        k = 160 / imageWidth;
                        imageHeight = imageHeight * k;
                        imageWidth = 160;
                }
                else
                {
                        k = 160 / imageHeight;
                        imageWidth = imageWidth * k;
                        imageHeight = 160;
                }
                
                document.all["ImgResized"].value = "1";
        }
        
        document.all["SendPic"].width = imageWidth;
        document.all["SendPic"].height = imageHeight;
        
        document.all["ImgWidth"].value = imageWidth;
        document.all["ImgHeight"].value = imageHeight;
}
</script>

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.