Click to See Complete Forum and Search --> : how to check if the picture already output
kennyTE
07-07-2007, 05:03 PM
Hi everyone,
Let say, i have a page that output this a several image, how to check weather a certain image already successfully load to user browser?
example image:
<div><img src='http://www.nasa.gov/images/content/84857main_EC04-0325-23_lg.jpg' width='336' height='280'></div>
i need to return a value is the picture finish load.
Thanks.
knowj
07-07-2007, 05:08 PM
to check a file is loaded you would need to use javascript as far as i am aware.
you could use file_exists($image_url); to check that the image is available to load but this would not check if the image is loaded in the browser window
temp.user123
07-07-2007, 05:13 PM
Yes, it would require JavaScript -- therefore, AJAX, to send the completion signal back to some PHP code of yours:
<img src='http://www.nasa.gov/images/content/84857main_EC04-0325-23_lg.jpg'
width='336' height='280'
onload="return ImageLoaded(this)">
kennyTE
07-07-2007, 05:17 PM
Thanks for reply.
Your advised is using javascript, Thanks.
But i'm doing a college project that involve in statistic.
i need to count the image loaded, it have to count when the image or swf file is fully loaded, which means a user already see the picture/swf file.
Any idea?
Thanks
kennyTE
07-07-2007, 05:24 PM
thanks temp.user123,
As u see, my code is an src to a php file where the image is generate on php file.
therefor, my code looks like this,
<?php
header("Content-type: application/x-javascript");
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
$data = "<img src='http://www.nasa.gov/images/content/84857main_EC04-0325-23_lg.jpg>";
echo "document.getElementById('nuffnangcenter').innerHTML = \"".$data."\"";
?>
As You say to correct my code as "onload="return ImageLoaded(this)".
Can it be done in PHP?
temp.user123
07-07-2007, 08:15 PM
The onload part goes in the HTML for JavaScript to execute. PHP only knows when the HTML content is sent to the browser. The code you're using allows the browser to independently retrieve the image as a separate request. So, PHP loses control at that point and it can't measure how long it takes the browser to load the image.
kennyTE
07-08-2007, 08:57 PM
as u say, we can track image by onload. But how to track flash swf onload?
image ----
<img src='http://www.nasa.gov/images/content/84857main_EC04-0325-23_lg.jpg'
width='336' height='280'
onload="return ImageLoaded(this)">
if SWF file?
<EMBED src='shrek.swf' width='336' height='280' onload='return ImageLoaded(this)'></embed>
seems does't work.
temp.user123
07-08-2007, 10:48 PM
IE appears to support onload for the embed tag.
Standards Information
This event is defined in HTML 4.0 .
Applies To
APPLET, BODY, EMBED, FRAME, FRAMESET, IFRAME, IMG, LINK, SCRIPT, window
MrCoder
07-09-2007, 05:11 AM
You don't need javascript at all.
Just create a PHP file that logs the user downloading the file then echo the file contents and correct headers for the file.
kennyTE
07-09-2007, 06:20 AM
temp.user123, you said onload Applies To
APPLET, BODY, EMBED, FRAME, FRAMESET, IFRAME, IMG, LINK, SCRIPT, window
thats seems great. but i try on embed, does't work.
my code :
<EMBED src='shrek.swf' width='336' height='280' onload='return ImageLoaded(this)'></embed>
please help.
-------------------------------
Thanks MrCoder. can u have some example for me? i dun understand how it works with your teory.
temp.user123
07-09-2007, 08:22 AM
Are you testing with an IE browser? ...which version? What I posted came from the MSDN website. So, as I said, it appears IE supports onload for the embed tag.
kennyTE
07-09-2007, 09:52 AM
i'm not going to use my web project only on IE. Is there a way that work on most browser?
temp.user123
07-09-2007, 11:22 AM
The flash object would have to support such an event itself.
I don't know anything about flash. Sorry.
Flash isnt native to the browser, javascript is.
That in itself should be enough of an indication to try another method and not to use Flash media.
kennyTE
07-09-2007, 06:09 PM
i really need to do some task after the flash SWF file is loaded. can some one help me? Note, those SWF file is not done by me, so i cant alter anything in the SWF document.