| 1234567891011121314151617181920212223242526272829303132333435363738 |
- var xmlHttp;
- var url="http://www.qq.com";
- function createXMLHttpRequest() { //创建一个xmlHttpRequest对象
- if (window.ActiveXObject) {
- xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
- }
- else if (window.XMLHttpRequest) {
- xmlHttp = new XMLHttpRequest();
- }
- }
- function loading(){
- createXMLHttpRequest();
- xmlHttp.onreadystatechange = handleStateChange; //请求状态改变事件触发handleStateChange功能
- xmlHttp.open("GET",url); //采用get方法提交数据
- xmlHttp.send(null);
- }
- function handleStateChange(){
- var loadcontent = document.createElement("div");
- loadcontent.style.width=document.body.clientWidth;
- loadcontent.style.height=document.documentElement.clientHeight;
- loadcontent.className="loading";
- document.body.appendChild(loadcontent);
- if(xmlHttp.readystate == 4){ //表示请求状态 4为完成
- if(xmlHttp.status == 200){ //http状态指示码,200表示ok
- loadcontent.style.display="none";
- }
- }
- else loadcontent.style.display="block";//若响应未完成的话,则显示loading..
- }
- if (document.all){
- window.attachEvent('onload',loading)//IE中,document.all在这里是起到判断是否是ie的功能
- }
- else{
- window.addEventListener('load',loading,false);//firefox
- }
|