473,699 Members | 2,628 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Testing Image Existence with side-effects

I'm trying to write a function to determine whether or not an image exists.

Most people recommend setting the onload event handler. That works like a
charm except that side-effective actions seem to be impossible. I can, as
nearly as I can tell, run alert and opera.postError (I test on IE, firefox,
and opera by the way). I've tried using the 'this' while in the event
handler, setting this.name, test.name, window.document .getElementById (test's
id).name. I just can't seem to find any means of using side effects inside
the event handler.

Below are several examples of things I've tried so far:

----------------------------------------
var test = new Image();
var id = imageUtils_getU niqueId();
alert("before-> " + window.document .body.childNode s.length);
test.id = id;
test.name = id;
test.onload = function () {window.documen t.body.appendCh ild(test);};
test.src = url;
while(!test.com plete){}
alert("after-> " + window.document .body.childNode s.length);

alert: before-> 12
alert: after-> 12
yet, the image still shows up on the page...
----------------------------------------

----------------------------------------
var test = new Image();
var didSucceed = false;
test.onload = function () {
didSucceed = true;
alert("load-> " + test.height);
};
test.src = url;
alert("post-> " + test.height);
return didSucceed;

alert: load-> 302
alert: post-> 0
returns false;
----------------------------------------

----------------------------------------
var test = new Image();
test.src = url;
while(!test.com plete){}
alert(test.heig ht);

alert: 0
----------------------------------------

----------------------------------------
var test = new Image();
test.id = imageUtils_getU niqueId();
window.document .body.appendChi ld(test);
test.src = url;
while(!test.com plete){}
alert(test.heig ht);

alert: 0
----------------------------------------

Any assistance would be greatly appreciated.

Thank you,
Harrison

--
Harrison Caudill BS BS | .^ www.hypersphere.org
Computer Science & Physics Graduate | | Me*Me=1
Georgia Institute of Technology | v' I'm just a normal guy
Oct 5 '05 #1
2 1917
alu

"Charles Harrison Caudill" wrote
I'm trying to write a function to determine whether or not an image exists.
Most people recommend setting the onload event handler. That works like a
charm except that side-effective actions seem to be impossible. I can, as
nearly as I can tell, run alert and opera.postError (I test on IE, firefox, and opera by the way). I've tried using the 'this' while in the event
handler, setting this.name, test.name, window.document .getElementById (test's id).name. I just can't seem to find any means of using side effects inside the event handler.

Below are several examples of things I've tried so far:

----------------------------------------
var test = new Image();
var id = imageUtils_getU niqueId();
alert("before-> " + window.document .body.childNode s.length);
test.id = id;
test.name = id;
test.onload = function () {window.documen t.body.appendCh ild(test);};
test.src = url;
while(!test.com plete){}
alert("after-> " + window.document .body.childNode s.length);

alert: before-> 12
alert: after-> 12
yet, the image still shows up on the page...
----------------------------------------

----------------------------------------
var test = new Image();
var didSucceed = false;
test.onload = function () {
didSucceed = true;
alert("load-> " + test.height);
};
test.src = url;
alert("post-> " + test.height);
return didSucceed;

alert: load-> 302
alert: post-> 0
returns false;
----------------------------------------

----------------------------------------
var test = new Image();
test.src = url;
while(!test.com plete){}
alert(test.heig ht);

alert: 0
----------------------------------------

----------------------------------------
var test = new Image();
test.id = imageUtils_getU niqueId();
window.document .body.appendChi ld(test);
test.src = url;
while(!test.com plete){}
alert(test.heig ht);

alert: 0
----------------------------------------

Any assistance would be greatly appreciated.

Thank you,
Harrison

Well, I don't know if this is any assistance, but I can at least start an
argument....

I don't think checking for test.complete within a while() loop is a great
idea; the loop process will likely override the image loading attempt,
therefore defeating the purpose.
And of course, before it *is* complete, there is no way to get the height as
a test for existence, as your code suggests.
I probably don't understand your reasoning completely, but the following
test works:

var test = new Image();
test.src = url
window.document .body.appendChi ld(test);
while(document. images.length < 1){}
alert(document. images.length);

-alu
Oct 6 '05 #2
I'm afraid it doesn't work. The results are the same if the image
exists or not. The problem is that the image loading process occurs
after the rest of the javascript on the page has been executed.
Consequently the only way I can find to detect the existence of an image
is to write every part of the html necessary after the image detection
needs to occur using javascript by running a

setTimeout('tes tThenWriteRestO fHTMLOrReschedu le()', 10);

or something like that.

Thanks though.

-harrison

PS This site doesn't seem to work properly in Opera. The submit button
doesn't appear.

::shrugs::
*** Sent via Developersdex http://www.developersdex.com ***
Oct 7 '05 #3

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

Similar topics

3
2304
by: Andrew | last post by:
Hi, I am thinking about ways for efficient techniques for isolation testing. Here is the problem as I see it: Complex OO systems are designed with massive number of dependencies between modules and classes. In most cases these dependencies end-up in external systems such as databases and OS. Overhead in designing systems with "could be stubbed" in mind is great, so in many cases dropped. I would appreciate if anyone interested in this...
9
1839
by: Ronald Fischer | last post by:
Assume the following JavaScript function: function bracketize(s) { return ''; } This function which doesn't assume anything about its argument except that it must be convertible to a string.
2
2040
by: mike | last post by:
I had a form like below that validated that a file was there before it would submit. <form name="attach" method="POST" action="run_this_pgm.cfm" enctype="multipart/form-data" onSubmit="return(validateData(this))"> <input type="file" name="txtFileToUpload"> <input type="submit" name="btnAdd" value="Add" class="form_button"> </form> function checkFile(frm)
6
1543
by: Vladimir | last post by:
Hi, I would like to inform you that a new version of the actiWATE (Actimind Web Application Testing Environment) is available for free-of-charge download on: http://www.actiWATE.com actiWATE is a freeware software platform intended to make test automation process simple and cost-effective. It consists of: - Advanced framework for writing test scripts in Java - Test Writing Assistant - Web browser plug-in module
5
2732
by: Brian | last post by:
Hello all.. Am working on an Air Hockey game... have an table loaded into a picture box. The borders of the table are slightly slanted. Am using hit testing lines with GDI+ to manipulate the puck moving around. I want the puck is bounce when it hits a border (specified by the hitlines). Retreieved some info on hit testing lines from Bob Powell's GDI+ FAQ (very useful!) but i'm fairly new at the idea of hit testing and am
13
2349
by: Neo Geshel | last post by:
I have examined about 80+ different upload scripts on the 'net, both in VB and C#, and none seem to do what I need them to do. Perhaps someone here can point me somewhere that Google hasn't reached yet (I have gone all the way to page 50 on Google's results!!). Here are my requirements: • I have a DataGrid. Everything will be done from here. Everything. No exceptions. Everything will also be done in VB, without any code-behind to...
12
1807
by: DC Gringo | last post by:
How do I test for existence of a file in the file system: If FileExists(myVariable & ".pdf") = True pnlMyPanel.Visible = True End If -- _____ DC G
7
4596
by: Ed Jay | last post by:
I'm trying to validate a form's file input elements using javascript, but I'm getting nowhere. How can javascript test if a file has been selected using a file form input element? -- Ed Jay (remove 'M' to respond by email)
18
2391
by: Andrew Wan | last post by:
I have been developing web applications with ASP & Javascript for a long time. I have been using Visual Studio 2003.NET. While VS2003 is okay for intellisense of ASP & Javascript, it's still not that great. One of the cons of ASP & Javascript is that they're both interpreted, which means one has twice the amount of work to do interms of syntax checking & semantic/runtime checking. Another bad thing is that ASP & Javascript doesn't have...
3
4965
by: Nebulism | last post by:
Hi everyone, I am working on a module for my GUI that shows one image with an index value below and would use a scrollbar to control which of the images are displayed. The images are stored in a successive folder in the format Pic#, i,e. Pic1, Pic2 etc. What I want to do is make a slider that is attached to a label which would output the slide number that is being looked at. I would use that number then to return the image of the slide...
0
8613
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9172
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9032
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8880
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7745
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6532
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5869
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4374
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3054
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.