如何在window.onload之前做点什么? [英] How to do something BEFORE window.onload?

查看:96
本文介绍了如何在window.onload之前做点什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个工作脚本,但是在

页面完成加载所有图像(可能需要一个

)之后,它会先执行。由于脚本放在window.onload i

明白它必须等待加载完成。


但是,我希望执行脚本所有

图像都有时间加载。那可行吗?怎么样?


-


V?nligen

Konrad

- -------------------------------------------------


睡眠 - 无效人使用的东西

作为咖啡的替代品


野心 - 一个不好的借口有足够的感觉懒得


------------------------ ---------------------------

解决方案

< BLOCKQUOTE>>这是可行的吗?

这取决于你的脚本在做什么。如果它解决任何页面

元素,它将是一个骰子游戏(50/50所请求的元素是

渲染与否)。

如何?



只需在要开始执行的位置插入脚本。


< body>

......

< script type =" text / javascript">

//你的剧本

< / script>

....


>>这是可行的吗?

这取决于你的脚本在做什么。如果它解决任何页面
元素,它将是一个骰子游戏(50/50所请求的元素是否呈现)。

如何?


只需在您要开始执行
的位置插入脚本。

< body>
.....
< ;脚本类型=" text / javascript">
//你的脚本
< / script>
...



东西是我永远不会执行代码。它被放在

函数window.onload中。并放在

文件的头部。但是代码没有被执行onload。在

"当我们到达页面时 - 它更多onload就像在当我们已经完成整个下载整个事情的时候时那样。


加载时间在这里非常重要,因为浏览器

加载大约100张图片。我希望在所有图片加载之前做一件事




我是否让自己更清楚或更困惑? :)


这是一个例子。尝试滚动一下,退出,然后再次返回页面,你将自动滚动

到你离开时的位置。


问题是你必须要等到所有图像都装满了
,这需要一段时间。
http://www.viltersten.com/sve/files/elvis.htm


-


V?nligen

Konrad

----- ----------------------------------------------


睡眠 - 无效人使用的东西

作为咖啡的替代品


野心 - 一个不好的借口/>
足够的感觉是懒惰的


--------------------------- ------------------------


我认为您的问题正在加载外部图像。加载来自其他网站的所有图片需要花费很多时间,而且它仍然是

loading :)


你可以加载使用XMLHttpRequest()加载页面后的图像...

,您将在加载页面后执行脚本。


I have a working script but it gets executed first after the
page has finished loading all the images (which may take a
while). Since the script is placed in window.onload i
understand it has to wait for the loading to get done.

However, i wish to execute the script BEFORE all the
images had time to get loaded. Is that doable? How?

--

V?nligen
Konrad
---------------------------------------------------

Sleep - thing used by ineffective people
as a substitute for coffee

Ambition - a poor excuse for not having
enough sense to be lazy

---------------------------------------------------

解决方案

> Is that doable?
It depends on what is your script doing. If it addresses any page
elements, it will be a dice game (50/50 the requested element is
rendered or not).

How?


Just insert your script at the point you want to start the execution.

<body>
......
<script type="text/javascript">
// your script
</script>
....


>> Is that doable?

It depends on what is your script doing. If it addresses any page
elements, it will be a dice game (50/50 the requested element is
rendered or not).

How?


Just insert your script at the point you want to start the
execution.

<body>
.....
<script type="text/javascript">
// your script
</script>
...


The thing is that i never execute the code. It is put in the
function "window.onload" and placed in the head of the
document. BUT the code is not executed "onload" as in
"as we get to the page" - it''s more "onload" as in "when
we have finished downloading the whole thing".

The loading time is of importance here since the browser
loads about 100 images. I wish to do a thing BEFORE all
the images have been loaded.

Did i make myself more clear or confused even more? :)

Here''s an example. Try to scroll a bit, exit, then come
back again to the page and you''ll be automatically scrolled
to the position you were at when you left.

The issue is that you have to wait until all the images has
been loaded, which takes a while.
http://www.viltersten.com/sve/files/elvis.htm

--

V?nligen
Konrad
---------------------------------------------------

Sleep - thing used by ineffective people
as a substitute for coffee

Ambition - a poor excuse for not having
enough sense to be lazy

---------------------------------------------------


I think that your problem is loading the external images. It takes too
much time to load all the images from another site and its still
loading :)

You can load the images after loading the page with XMLHttpRequest()...
that you will execute your script after loading the page.


这篇关于如何在window.onload之前做点什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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