Connecting Tech Pros Worldwide Help | Site Map

Looking for an event trigger

Cleverbum@hotmail.com
Guest
 
Posts: n/a
#1: Oct 11 '06
I'm hoping to execute some code "when the page has completely finished
loading" by which I mean the page and all the images on it, does anyone
know of a way to do this?

Mateusz Markowski
Guest
 
Posts: n/a
#2: Oct 11 '06

re: Looking for an event trigger


Clever...@hotmail.com napisal(a):
Quote:
I'm hoping to execute some code "when the page has completely finished
loading" by which I mean the page and all the images on it, does anyone
know of a way to do this?
You can do it using AJAX. Put some java script code into page which
will make a request to your server when page is loaded to inform PHP
script that whole page's been loaded.

ASM
Guest
 
Posts: n/a
#3: Oct 11 '06

re: Looking for an event trigger


Cleverbum@hotmail.com a écrit :
Quote:
I'm hoping to execute some code "when the page has completely finished
loading" by which I mean the page and all the images on it, does anyone
know of a way to do this?
<script type="text/javascript">

function sthg() {
document.body.style.background='orange';
}

onload = function() { sthg(); alert('all loaded'); };
</script>


does alert fires before all images loaded ?
Jerry Stuckle
Guest
 
Posts: n/a
#4: Oct 11 '06

re: Looking for an event trigger


Cleverbum@hotmail.com wrote:
Quote:
I'm hoping to execute some code "when the page has completely finished
loading" by which I mean the page and all the images on it, does anyone
know of a way to do this?
>
Are you looking to execute some code on the server or the client? What
are you actually trying to do?

Remember - PHP is server side only. It has no direct contact with the
client. All it knows is when it's passed its data off to the web server
for sending to the client. It doesn't know what happens after that -
not even if the browser is closed or the connection dropped before the
page completed loading.

You can do it in Javascript on the client, and as Mateusz indicated you
can use AJAX to call a function back on the server.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Chung Leong
Guest
 
Posts: n/a
#5: Oct 11 '06

re: Looking for an event trigger



ASM wrote:
Quote:
Cleverbum@hotmail.com a écrit :
Quote:
I'm hoping to execute some code "when the page has completely finished
loading" by which I mean the page and all the images on it, does anyone
know of a way to do this?
>
<script type="text/javascript">
>
function sthg() {
document.body.style.background='orange';
}
>
onload = function() { sthg(); alert('all loaded'); };
</script>
>
>
does alert fires before all images loaded ?
No, onload for the document fires when the HTML file is loaded. Img
tags have their own onload handlers. AFAIK not events are emitted on
things like background images.

Cleverbum@hotmail.com
Guest
 
Posts: n/a
#6: Oct 11 '06

re: Looking for an event trigger



Jerry Stuckle wrote:
Quote:
Cleverbum@hotmail.com wrote:
Quote:
I'm hoping to execute some code "when the page has completely finished
loading" by which I mean the page and all the images on it, does anyone
know of a way to do this?
>
Are you looking to execute some code on the server or the client? What
are you actually trying to do?
>
Remember - PHP is server side only. It has no direct contact with the
client. All it knows is when it's passed its data off to the web server
for sending to the client. It doesn't know what happens after that -
not even if the browser is closed or the connection dropped before the
page completed loading.
>
You can do it in Javascript on the client, and as Mateusz indicated you
can use AJAX to call a function back on the server.
>
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
I was hoping to redirect the client to the next page once the first had
been loaded, so I guess some clientside javascript would be sufficient?

Jerry Stuckle
Guest
 
Posts: n/a
#7: Oct 11 '06

re: Looking for an event trigger


Cleverbum@hotmail.com wrote:
Quote:
Jerry Stuckle wrote:
>
Quote:
>>Cleverbum@hotmail.com wrote:
>>
Quote:
>>>I'm hoping to execute some code "when the page has completely finished
>>>loading" by which I mean the page and all the images on it, does anyone
>>>know of a way to do this?
>>>
>>
>>Are you looking to execute some code on the server or the client? What
>>are you actually trying to do?
>>
>>Remember - PHP is server side only. It has no direct contact with the
>>client. All it knows is when it's passed its data off to the web server
>>for sending to the client. It doesn't know what happens after that -
>>not even if the browser is closed or the connection dropped before the
>>page completed loading.
>>
>>You can do it in Javascript on the client, and as Mateusz indicated you
>>can use AJAX to call a function back on the server.
>>
>>--
>>==================
>>Remove the "x" from my email address
>>Jerry Stuckle
>>JDS Computer Training Corp.
>>jstucklex@attglobal.net
>>==================
>
>
I was hoping to redirect the client to the next page once the first had
been loaded, so I guess some clientside javascript would be sufficient?
>
You could, but then why even load the first page? It will just flash up
there then go to the next page.

If I were the client I would be very upset about this.

But if you insist, you can do it with an html redirect. Check the
alt.html newsgroup for help on how to do it.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Cleverbum@hotmail.com
Guest
 
Posts: n/a
#8: Oct 12 '06

re: Looking for an event trigger



Jerry Stuckle wrote:
Quote:
Cleverbum@hotmail.com wrote:
Quote:
Jerry Stuckle wrote:
Quote:
>Cleverbum@hotmail.com wrote:
>
>>I'm hoping to execute some code "when the page has completely finished
>>loading" by which I mean the page and all the images on it, does anyone
>>know of a way to do this?
>>
>
>Are you looking to execute some code on the server or the client? What
>are you actually trying to do?
>
>Remember - PHP is server side only. It has no direct contact with the
>client. All it knows is when it's passed its data off to the web server
>for sending to the client. It doesn't know what happens after that -
>not even if the browser is closed or the connection dropped before the
>page completed loading.
>
>You can do it in Javascript on the client, and as Mateusz indicated you
>can use AJAX to call a function back on the server.
>
>--
>==================
>Remove the "x" from my email address
>Jerry Stuckle
>JDS Computer Training Corp.
>jstucklex@attglobal.net
>==================

I was hoping to redirect the client to the next page once the first had
been loaded, so I guess some clientside javascript would be sufficient?
>
You could, but then why even load the first page? It will just flash up
there then go to the next page.
>
If I were the client I would be very upset about this.
>
But if you insist, you can do it with an html redirect. Check the
alt.html newsgroup for help on how to do it.
>
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Well the first page does the processing that the second page needs
before it can be displayed, the processing is done by pages loaded
within image tags, there are over 4,000 of them and the processing time
will obviously vary, hence why I wanted the trigger to activate once
the page and all the images had loaded.

Jerry Stuckle
Guest
 
Posts: n/a
#9: Oct 12 '06

re: Looking for an event trigger


Cleverbum@hotmail.com wrote:
Quote:
Jerry Stuckle wrote:
>
Quote:
>>Cleverbum@hotmail.com wrote:
>>
Quote:
>>>Jerry Stuckle wrote:
>>>
>>>
>>>>Cleverbum@hotmail.com wrote:
>>>>
>>>>
>>>>>I'm hoping to execute some code "when the page has completely finished
>>>>>loading" by which I mean the page and all the images on it, does anyone
>>>>>know of a way to do this?
>>>>>
>>>>
>>>>Are you looking to execute some code on the server or the client? What
>>>>are you actually trying to do?
>>>>
>>>>Remember - PHP is server side only. It has no direct contact with the
>>>>client. All it knows is when it's passed its data off to the web server
>>>>for sending to the client. It doesn't know what happens after that -
>>>>not even if the browser is closed or the connection dropped before the
>>>>page completed loading.
>>>>
>>>>You can do it in Javascript on the client, and as Mateusz indicated you
>>>>can use AJAX to call a function back on the server.
>>>>
>>>>--
>>>>==================
>>>>Remove the "x" from my email address
>>>>Jerry Stuckle
>>>>JDS Computer Training Corp.
>>>>jstucklex@attglobal.net
>>>>==================
>>>
>>>
>>>I was hoping to redirect the client to the next page once the first had
>>>been loaded, so I guess some clientside javascript would be sufficient?
>>>
>>
>>You could, but then why even load the first page? It will just flash up
>>there then go to the next page.
>>
>>If I were the client I would be very upset about this.
>>
>>But if you insist, you can do it with an html redirect. Check the
>>alt.html newsgroup for help on how to do it.
>>
>
>
Well the first page does the processing that the second page needs
before it can be displayed, the processing is done by pages loaded
within image tags, there are over 4,000 of them and the processing time
will obviously vary, hence why I wanted the trigger to activate once
the page and all the images had loaded.
>
OK, I understand the pages doing the processing. But why would you send
any data to the client if it's not meant to be seen, anyway?

And in a case like that, why would you care if the page is loaded or not?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Cleverbum@hotmail.com
Guest
 
Posts: n/a
#10: Oct 12 '06

re: Looking for an event trigger



Jerry Stuckle wrote:
Quote:
Cleverbum@hotmail.com wrote:
Quote:
Jerry Stuckle wrote:
Quote:
>Cleverbum@hotmail.com wrote:
>
>>Jerry Stuckle wrote:
>>
>>
>>>Cleverbum@hotmail.com wrote:
>>>
>>>
>>>>I'm hoping to execute some code "when the page has completely finished
>>>>loading" by which I mean the page and all the images on it, does anyone
>>>>know of a way to do this?
>>>>
>>>
>>>Are you looking to execute some code on the server or the client? What
>>>are you actually trying to do?
>>>
>>>Remember - PHP is server side only. It has no direct contact with the
>>>client. All it knows is when it's passed its data off to the web server
>>>for sending to the client. It doesn't know what happens after that -
>>>not even if the browser is closed or the connection dropped before the
>>>page completed loading.
>>>
>>>You can do it in Javascript on the client, and as Mateusz indicated you
>>>can use AJAX to call a function back on the server.
>>>
>>>--
>>>==================
>>>Remove the "x" from my email address
>>>Jerry Stuckle
>>>JDS Computer Training Corp.
>>>jstucklex@attglobal.net
>>>==================
>>
>>
>>I was hoping to redirect the client to the next page once the first had
>>been loaded, so I guess some clientside javascript would be sufficient?
>>
>
>You could, but then why even load the first page? It will just flash up
>there then go to the next page.
>
>If I were the client I would be very upset about this.
>
>But if you insist, you can do it with an html redirect. Check the
>alt.html newsgroup for help on how to do it.
>

Well the first page does the processing that the second page needs
before it can be displayed, the processing is done by pages loaded
within image tags, there are over 4,000 of them and the processing time
will obviously vary, hence why I wanted the trigger to activate once
the page and all the images had loaded.
>
OK, I understand the pages doing the processing. But why would you send
any data to the client if it's not meant to be seen, anyway?
>
And in a case like that, why would you care if the page is loaded or not?
>
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
The page needs to finish loading for all of the processing to complete.
Each image on the first page corresponds to a certain portion of the
work that needed doing before the second page is shown. If the second
page is shown before the first one is finished the information on it
will be wrong.
I've done the data processing this way as my host has a maximum
execution time of 30 seconds and only supports web languages - not
things like java/c.
The images also show information about what happened in the process,
which is useful for debugging, but will most likely be ignored by the
client.

Jerry Stuckle
Guest
 
Posts: n/a
#11: Oct 13 '06

re: Looking for an event trigger


Cleverbum@hotmail.com wrote:
Quote:
Jerry Stuckle wrote:
>
Quote:
>>Cleverbum@hotmail.com wrote:
>>
Quote:
>>>Jerry Stuckle wrote:
>>>
>>>
>>>>Cleverbum@hotmail.com wrote:
>>>>
>>>>
>>>>>Jerry Stuckle wrote:
>>>>>
>>>>>
>>>>>
>>>>>>Cleverbum@hotmail.com wrote:
>>>>>>
>>>>>>
>>>>>>
>>>>>>>I'm hoping to execute some code "when the page has completely finished
>>>>>>>loading" by which I mean the page and all the images on it, does anyone
>>>>>>>know of a way to do this?
>>>>>>>
>>>>>>
>>>>>>Are you looking to execute some code on the server or the client? What
>>>>>>are you actually trying to do?
>>>>>>
>>>>>>Remember - PHP is server side only. It has no direct contact with the
>>>>>>client. All it knows is when it's passed its data off to the web server
>>>>>>for sending to the client. It doesn't know what happens after that -
>>>>>>not even if the browser is closed or the connection dropped before the
>>>>>>page completed loading.
>>>>>>
>>>>>>You can do it in Javascript on the client, and as Mateusz indicated you
>>>>>>can use AJAX to call a function back on the server.
>>>>>>
>>>>>>--
>>>>>>==================
>>>>>>Remove the "x" from my email address
>>>>>>Jerry Stuckle
>>>>>>JDS Computer Training Corp.
>>>>>>jstucklex@attglobal.net
>>>>>>==================
>>>>>
>>>>>
>>>>>I was hoping to redirect the client to the next page once the first had
>>>>>been loaded, so I guess some clientside javascript would be sufficient?
>>>>>
>>>>
>>>>You could, but then why even load the first page? It will just flash up
>>>>there then go to the next page.
>>>>
>>>>If I were the client I would be very upset about this.
>>>>
>>>>But if you insist, you can do it with an html redirect. Check the
>>>>alt.html newsgroup for help on how to do it.
>>>>
>>>
>>>
>>>Well the first page does the processing that the second page needs
>>>before it can be displayed, the processing is done by pages loaded
>>>within image tags, there are over 4,000 of them and the processing time
>>>will obviously vary, hence why I wanted the trigger to activate once
>>>the page and all the images had loaded.
>>>
>>
>>OK, I understand the pages doing the processing. But why would you send
>>any data to the client if it's not meant to be seen, anyway?
>>
>>And in a case like that, why would you care if the page is loaded or not?
>>
>>--
>>==================
>>Remove the "x" from my email address
>>Jerry Stuckle
>>JDS Computer Training Corp.
>>jstucklex@attglobal.net
>>==================
>
The page needs to finish loading for all of the processing to complete.
Each image on the first page corresponds to a certain portion of the
work that needed doing before the second page is shown. If the second
page is shown before the first one is finished the information on it
will be wrong.
I've done the data processing this way as my host has a maximum
execution time of 30 seconds and only supports web languages - not
things like java/c.
The images also show information about what happened in the process,
which is useful for debugging, but will most likely be ignored by the
client.
>
OK, but there's no guarantee just because you send something to the
client that it will be displayed immediately. It can be buffered by PHP
and the web server. You can get around this most of the time with
ob_flush() and flush(), but additionally, the browser may not display
the data until the page is loaded.

With images it's even harder. When you sent the <imgtag you are not
sending the image itself. The browser has to receive the tag, then go
back to the server and fetch the image. It may do that immediately on
receipt of the tag, or it may wait until the page is loaded.

The bottom line is - sending images like this for progress is at best a
hit and miss proposition.

Maybe you can get around your problem (and the timeout problem) with
help from javascript. Instead of trying to do everything in one page,
do a little processing and send a page to the client (including the
image you wish). In that one use the onload property for the body to
load the next page in the sequence.

That way your client will see the images, and since you've broken up
your processing you don't run into the 30s limit.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Cleverbum@hotmail.com
Guest
 
Posts: n/a
#12: Oct 13 '06

re: Looking for an event trigger


I realise that once the html in the page has been sent the browser
still needs to load all of the images, that's why the onload won't
work, and why I was looking for a trigger that fires "once the page and
all the images on it have loaded"

I'm reluctant to change the language of the processing script as it's
taken me quite some time to write it all, at the moment I've just got a
link at the bottom of the processing page saying "once the above box is
completely full please click here", unless there is something which can
do that automatically I think I will just forget about it and rely on
someone's built in clicking skills.

Chung Leong
Guest
 
Posts: n/a
#13: Oct 13 '06

re: Looking for an event trigger



Cleverbum@hotmail.com wrote:
Quote:
I realise that once the html in the page has been sent the browser
still needs to load all of the images, that's why the onload won't
work, and why I was looking for a trigger that fires "once the page and
all the images on it have loaded"
>
I'm reluctant to change the language of the processing script as it's
taken me quite some time to write it all, at the moment I've just got a
link at the bottom of the processing page saying "once the above box is
completely full please click here", unless there is something which can
do that automatically I think I will just forget about it and rely on
someone's built in clicking skills.
As mentioned already, each img tag would emit an onload event. The
event doesn't bubble up so you have to add onload=" ... " to each tag.
Now, if you just increment a counter as the images load and do a
redirect when it reaches the total, you'll have what you need. Simple,
no?

Mateusz Markowski
Guest
 
Posts: n/a
#14: Oct 13 '06

re: Looking for an event trigger



Chung Leong napisal(a):
Quote:
Cleverbum@hotmail.com wrote:
Quote:
I realise that once the html in the page has been sent the browser
still needs to load all of the images, that's why the onload won't
work, and why I was looking for a trigger that fires "once the page and
all the images on it have loaded"

I'm reluctant to change the language of the processing script as it's
taken me quite some time to write it all, at the moment I've just got a
link at the bottom of the processing page saying "once the above box is
completely full please click here", unless there is something which can
do that automatically I think I will just forget about it and rely on
someone's built in clicking skills.
>
As mentioned already, each img tag would emit an onload event. The
event doesn't bubble up so you have to add onload=" ... " to each tag.
Now, if you just increment a counter as the images load and do a
redirect when it reaches the total, you'll have what you need. Simple,
no?

function waitForImages()
{
while(!document.images[document.images.length-1].complete);
document.location.href = '/loaded';
}

waitForImages();

Isn't easier?

Chung Leong
Guest
 
Posts: n/a
#15: Oct 13 '06

re: Looking for an event trigger


Mateusz Markowski wrote:
Quote:
Chung Leong napisal(a):
Quote:
Cleverbum@hotmail.com wrote:
Quote:
I realise that once the html in the page has been sent the browser
still needs to load all of the images, that's why the onload won't
work, and why I was looking for a trigger that fires "once the page and
all the images on it have loaded"
>
I'm reluctant to change the language of the processing script as it's
taken me quite some time to write it all, at the moment I've just got a
link at the bottom of the processing page saying "once the above box is
completely full please click here", unless there is something which can
do that automatically I think I will just forget about it and rely on
someone's built in clicking skills.
As mentioned already, each img tag would emit an onload event. The
event doesn't bubble up so you have to add onload=" ... " to each tag.
Now, if you just increment a counter as the images load and do a
redirect when it reaches the total, you'll have what you need. Simple,
no?
>
>
function waitForImages()
{
while(!document.images[document.images.length-1].complete);
document.location.href = '/loaded';
}
>
waitForImages();
>
Isn't easier?
I'm pretty sure that would cause the browser to freeze.

Mateusz Markowski
Guest
 
Posts: n/a
#16: Oct 13 '06

re: Looking for an event trigger



Chung Leong napisal(a):
Quote:
Mateusz Markowski wrote:
Quote:
Chung Leong napisal(a):
Quote:
Cleverbum@hotmail.com wrote:
I realise that once the html in the page has been sent the browser
still needs to load all of the images, that's why the onload won't
work, and why I was looking for a trigger that fires "once the page and
all the images on it have loaded"

I'm reluctant to change the language of the processing script as it's
taken me quite some time to write it all, at the moment I've just got a
link at the bottom of the processing page saying "once the above box is
completely full please click here", unless there is something which can
do that automatically I think I will just forget about it and rely on
someone's built in clicking skills.
>
As mentioned already, each img tag would emit an onload event. The
event doesn't bubble up so you have to add onload=" ... " to each tag.
Now, if you just increment a counter as the images load and do a
redirect when it reaches the total, you'll have what you need. Simple,
no?

function waitForImages()
{
while(!document.images[document.images.length-1].complete);
document.location.href = '/loaded';
}

waitForImages();

Isn't easier?
>
I'm pretty sure that would cause the browser to freeze.
True, works only on Opera.

Closed Thread


Similar PHP bytes