页面加载状态 [英] Page loading status

查看:67
本文介绍了页面加载状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么办法知道浏览器加载页面的距离吗?

Is there any way to know how far browser loaded the page?

使用JavaScript或浏览器本机函数.

Either by using JavaScript or browser native functions.

基于页面状态,我要构建进度条.

Based on the page status i want to build progress bar.

推荐答案

我不是100%确信这会起作用,但是..这是理论所在:

I'm not 100% sure this will work, but.. here is the theory:

首先,不要在页面加载之前停止JavaScript的运行.意思是,不要使用window.ready document.ready等.

First of all, don't stop JavaScript running until the page has loaded. Meaning, don't use window.ready document.ready etc..

在页面顶部初始化一个名为load或something的JavaScript变量,并将其设置为0.

At the top of the page initialise a JavaScript variable called loaded or something and set it to 0.

var loaded = 0;

在整个页面增量加载到您认为正确的百分比的不同点上.

Throughout the page increment loaded at different points that you consider to be at the correct percentages.

例如,在您认为一半页面将被加载到代码集loaded = 50;中之后.

For example, after you think half the page would have been loaded in the code set loaded = 50;.

等等.

正如我所说的,这只是一个概念.

As I say, this is just a concept.

这篇关于页面加载状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆