loading.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. var xmlHttp;
  2. var url="http://www.qq.com";
  3. function createXMLHttpRequest() { //����һ��xmlHttpRequest����
  4. if (window.ActiveXObject) {
  5. xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  6. }
  7. else if (window.XMLHttpRequest) {
  8. xmlHttp = new XMLHttpRequest();
  9. }
  10. }
  11. function loading(){
  12. createXMLHttpRequest();
  13. xmlHttp.onreadystatechange = handleStateChange; //����״̬�ı��¼�����handleStateChange����
  14. xmlHttp.open("GET",url); //����get�����ύ���
  15. xmlHttp.send(null);
  16. }
  17. function handleStateChange(){
  18. var loadcontent = document.createElement("div");
  19. loadcontent.style.width=document.body.clientWidth;
  20. loadcontent.style.height=document.documentElement.clientHeight;
  21. loadcontent.className="loading";
  22. document.body.appendChild(loadcontent);
  23. if(xmlHttp.readystate == 4){ //��ʾ����״̬ 4Ϊ���
  24. if(xmlHttp.status == 200){ //http״ָ̬ʾ�룬200��ʾok
  25. loadcontent.style.display="none";
  26. }
  27. }
  28. else loadcontent.style.display="block";//����Ӧδ��ɵĻ�������ʾloading..
  29. }
  30. if (document.all){
  31. window.attachEvent('onload',loading)//IE��,document.all�����������ж��Ƿ���ie�Ĺ���
  32. }
  33. else{
  34. window.addEventListener('load',loading,false);//firefox
  35. }