在页面下载时收到通知 [英] Being notified as the page downloads

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

问题描述

-----开始PGP签名消息-----

哈希:SHA1


假设我有一段Javascript改变了页面上的HTML。 (在

命令解决CSS错误。)


我可以从BODY onload事件处理程序调用它。然而,这意味着

对于慢速链接上的大页面,用户将不得不坐下来,

观看未转换的页面进来---然后一旦它完成,

就会暂停,然后页面将变为转换后的

版本。这不是最理想的。


我想做的是在每一块HTML上运行变换器,因为它从服务器到达
。当然,我只能为

完整的DOM节点做这件事。


显而易见的方法是:

(a)设置一个每500ms运行一次的计时器

(b)跟踪我们已经走了多远

(c)当计时器火,看看是否有任何新节点到达,

处理它们,并返回


这有点繁琐,如果浏览器也会失败地方完整

DOM树中的节点(我不知道是否有)。


另一种方法是放置onLoad处理程序在需要转换的每个HTML

元素上,但这需要页面的

作者的大量工作(我想避免)。 />

有没有人有任何建议?


- -

+ - David Given --McQ - +

| dg@cowlark.com |变得不朽或死!

| (dg@tao-group.com)|

+ - www.cowlark。 com - +

----- BEGIN PGP SIGNATURE -----

版本:GnuPG v1.4.2(GNU / Linux)


iD8DBQFDXjjmf9E0noFvlzgRAr8AAJ4rs60djRuldMw0D0NYcy JXZKE36ACgg5up

fPv2rI5f3MZtAfMNLAeZLTk =

= 0moV

----- END PGP SIGNATURE-- ---

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Say I have a piece of Javascript that transforms the HTML on a page. (In
order to work around CSS bugs.)

I could invoke this from the BODY onload event handler. However, this means
that for a large page on a slow link, the user''s going to have to sit and
watch the untransformed page come in --- and then once it''s finished,
there''ll be a pause, and then the page will change to the transformed
version. This is suboptimal.

What I''d like to do is to run the transformer on each chunk of HTML as it
arrives from the server. Naturally, I''d only be able to do this for
complete DOM nodes.

The obvious approach is to:

(a) set a timer that runs every 500ms
(b) keep track of how far we''ve got
(c) when the timer fires, look to see if any new nodes have arrived,
process them, and return

This is a bit fiddly, and will also fail if the browser places complete
nodes in the DOM tree (and I don''t know if any do).

An alternate approach would be to put an onLoad handler on every HTML
element that needs transforming, but this requires a lot of work by the
author of the page (which I''d like to avoid).

Does anyone have any suggestions?

- --
+- David Given --McQ-+
| dg@cowlark.com | Become immortal or die!
| (dg@tao-group.com) |
+- www.cowlark.com --+
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)

iD8DBQFDXjjmf9E0noFvlzgRAr8AAJ4rs60djRuldMw0D0NYcy JXZKE36ACgg5up
fPv2rI5f3MZtAfMNLAeZLTk=
=0moV
-----END PGP SIGNATURE-----

推荐答案

David Given说:
David Given said:
说我有一段Javascript改变了页面上的HTML。 (在
中解决CSS错误。)
Say I have a piece of Javascript that transforms the HTML on a page. (In
order to work around CSS bugs.)




在客户端做很多工作要做什么

在服务器端很简单。使用正确的工具。



That''s an awful lot of work on the client side to do what would
be simple on the server side. Use the right tool for the job.


-----开始PGP签名消息-----

哈希:SHA1


文章< dj ********* @ drn.newsguy.com>,

Lee< RE ** ************@cox.net>写道:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

In article <dj*********@drn.newsguy.com>,
Lee <RE**************@cox.net> writes:
David Given说:
David Given said:
说我有一段Javascript可以转换页面上的HTML。 (在
中解决CSS错误。)
Say I have a piece of Javascript that transforms the HTML on a page. (In
order to work around CSS bugs.)



在客户端做很多工作要做的事情很简单服务器端。使用正确的工具。



That''s an awful lot of work on the client side to do what would
be simple on the server side. Use the right tool for the job.




是的,我也爱你。


我需要转换HTML因为(a)只有客户知道怎么做

(因为我正在改变它取决于客户端状态---对于

例子,浏览器窗口宽度),以及(b)当客户有多余的时候,我为什么要使用服务器的宝贵的CPU周期呢?


- -

+ - David Given --McQ- +我从一开始就认为这将是

| dg@cowlark.com |结束;我是对的,因为它不是一半结束

| (dg@tao-group.com)| 。然而" --- Boyle Roche先生

+ - www.cowlark.com - +

-----开始PGP签名-----

版本:GnuPG v1.4.2(GNU / Linux)


iD8DBQFDXmWdf9E0noFvlzgRArlEAKCFjofWviF7T82A8E42bQ + qsO1uXACgk96N

QU0jtG7VGaPdjFV7su2G2ik =

= ztYq

----- END PGP SIGNATURE -----



Yes, I love you too.

I need to transform the HTML because (a) only the client knows how to do it
(because how I''m transforming it depends on the client state --- for
example, the browser window width), and (b) why should I use my server''s
precious CPU cycles when the client''s got lots to spare?

- --
+- David Given --McQ-+ "I concluded from the beginning that this would be
| dg@cowlark.com | the end; and I am right, for it is not half over
| (dg@tao-group.com) | yet." --- Sir Boyle Roche
+- www.cowlark.com --+
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)

iD8DBQFDXmWdf9E0noFvlzgRArlEAKCFjofWviF7T82A8E42bQ +qsO1uXACgk96N
QU0jtG7VGaPdjFV7su2G2ik=
=ztYq
-----END PGP SIGNATURE-----


David Given说:
David Given said:

----- BEGIN PGP签名消息-----
哈希:SHA1

文章< dj ********* @ drn.newsguy.com>,
Lee< RE ********** ****@cox.net>写道:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

In article <dj*********@drn.newsguy.com>,
Lee <RE**************@cox.net> writes:
David Given说:
David Given said:
说我有一段Javascript可以转换页面上的HTML。 (在
中解决CSS错误。)
Say I have a piece of Javascript that transforms the HTML on a page. (In
order to work around CSS bugs.)



在客户端做很多工作要做的事情很简单服务器端。使用正确的工具。



That''s an awful lot of work on the client side to do what would
be simple on the server side. Use the right tool for the job.



是的,我也爱你。

我需要转换HTML,因为(a)只有客户知道如何要做到这一点
(因为我正在改变它取决于客户端状态---例如,浏览器窗口宽度),以及(b)我为什么要使用我的服务器?
宝贵的CPU周期,当客户有很多空闲时间?



Yes, I love you too.

I need to transform the HTML because (a) only the client knows how to do it
(because how I''m transforming it depends on the client state --- for
example, the browser window width), and (b) why should I use my server''s
precious CPU cycles when the client''s got lots to spare?




您可以轻松查询客户端的浏览器,找出所有你的内容

需要知道,然后发送自定义页面。在服务器上而不是在客户端上进行操作的原因应该是显而易见的。

如果没有,你就会在你的头上。



You can easily query the client''s browser to find out all that you
need to know, then send the customized page. The reasons for doing
it on the server instead of on the client should be obvious.
If not, you''re in way over your head.


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

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