js 网页加载状态判断以及中止加载

爬虫爬网页时,有时页面一直在加载中,其网页加载状态document.readyState分为:

  1. uninitialized:(Uninitialized) the send( ) method has not yet been invoked. (未初始化)还没有调用send()方法;
  2. loading:the send( ) method has been invoked, request in progress. (载入)已调用send()方法,正在发送请求;
  3. loaded:the send( ) method has completed, entire response received. (载入完成)send()方法执行完成,已经接收到全部响应内容;
  4. interactive:the response is being parsed. (交互)正在解析响应内容;
  5. completed:the response has been parsed, is ready for harvesting. (完成)响应内容解析完成,可以在客户端调用了;

如果要停止加载,则可以执行js脚本:window.stop()

	//当页面一直在加载中(比如引用某个图片或脚本未完成),但所需内容已显示出来
  if (document.readyState == 'interactive') 
   	{
   		window.stop()`
   	}

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

参考资料 js 判断页面加载状态

原文地址:https://www.cnblogs.com/zoulei0718/p/14315574.html