473,406 Members | 2,336 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Looking for an event trigger

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?

Oct 11 '06 #1
16 1501
Clever...@hotmail.com napisal(a):
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.

Oct 11 '06 #2
ASM
Cl*******@hotmail.com a écrit :
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 ?
Oct 11 '06 #3
Cl*******@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.
js*******@attglobal.net
==================
Oct 11 '06 #4

ASM wrote:
Cl*******@hotmail.com a écrit :
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.

Oct 11 '06 #5

Jerry Stuckle wrote:
Cl*******@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.
js*******@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?

Oct 11 '06 #6
Cl*******@hotmail.com wrote:
Jerry Stuckle wrote:
>>Cl*******@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.
js*******@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.
js*******@attglobal.net
==================
Oct 11 '06 #7

Jerry Stuckle wrote:
Cl*******@hotmail.com wrote:
Jerry Stuckle wrote:
>Cl*******@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.
js*******@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.
js*******@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.

Oct 12 '06 #8
Cl*******@hotmail.com wrote:
Jerry Stuckle wrote:
>>Cl*******@hotmail.com wrote:
>>>Jerry Stuckle wrote:
Cl*******@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.
js*******@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.
js*******@attglobal.net
==================
Oct 12 '06 #9

Jerry Stuckle wrote:
Cl*******@hotmail.com wrote:
Jerry Stuckle wrote:
>Cl*******@hotmail.com wrote:

Jerry Stuckle wrote:
Cl*******@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.
js*******@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.
js*******@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.

Oct 12 '06 #10
Cl*******@hotmail.com wrote:
Jerry Stuckle wrote:
>>Cl*******@hotmail.com wrote:
>>>Jerry Stuckle wrote:
Cl*******@hotmail.com wrote:
>Jerry Stuckle wrote:
>
>
>
>>Cl*******@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.
>>js*******@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.
js*******@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.
js*******@attglobal.net
==================
Oct 13 '06 #11
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.

Oct 13 '06 #12


On Oct 13, 11:02 am, Clever...@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"
"all the images" are part of the page so that the page isn't finished
loading until all the images 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.
window.onload = iAmFinished;
function iAmFinished(){
alert('The only way you will see this alert before all images are
loaded is if there is an error with one of the image files')
}

--
Randy

Oct 13 '06 #13

Cl*******@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?

Oct 13 '06 #14

Chung Leong napisal(a):
Cl*******@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?

Oct 13 '06 #15
Mateusz Markowski wrote:
Chung Leong napisal(a):
Cl*******@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.

Oct 13 '06 #16

Chung Leong napisal(a):
Mateusz Markowski wrote:
Chung Leong napisal(a):
Cl*******@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.

Oct 13 '06 #17

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: R. Rajesh Jeba Anbiah | last post by:
I have Googled a lot, but couldn't still find the answer... I could see, I can trigger the "click" event like: button_object.Click() But, I need to trigger the onChange() of select options. I...
3
by: MikeY | last post by:
Hi Everyone, I am working in C#, windows forms.My question is this. All my button dynamic controls properties are present and accounted for except for the"FlatStyle" properties. I can't seem to...
4
by: Peter Lin | last post by:
Dear all; I need to monitor a xml file so that I can update my data in hashtable, but the problem is it will trigger more than one event for a lastwrite action(I trigger this action by add...
2
by: Owin | last post by:
Hi all, I've created an User control. It's an extension of a textbox wich has some extra properties so that validation becomes a lot faster. The control wordks great if autopostback is on. When...
8
by: Steve Schroeder | last post by:
For some reason I cannot get the OnSelectedIndexChanged event to fire for a listbox I have on a page. I'm able to populate the listbox with data from a stored procedure, but cannot trigger the...
3
by: rmorvay | last post by:
I allow users to click a datagrid row and it spawns another browser page to allow edits to the data in that row. Once they update the data, it is committed to the database and the form is closed. ...
3
by: George | last post by:
Hi, I have searched on the net quite a bit, but the more I read, the more confused I get. I want to see if I can raise an event out side of the class. I believe this can be done in VB (at...
2
by: cumars | last post by:
Hello Friends, I want to trigger both the click event and double click event in a single button separately. (i.e.) the user can trigger both the single click and the double...
15
by: Cleverbum | last post by:
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?
4
by: LyzH | last post by:
Someone else had a question on how to emulate a mouse click. I tried posting in that thread but I have something of a twist on this problem and I'm really in trouble here! If I don't get help...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.