wood burning stoves 2.0*
The moose likes HTML, CSS and JavaScript and the fly likes How to know img tag src attribute loaded completely by action Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "How to know img tag src attribute loaded completely by action" Watch "How to know img tag src attribute loaded completely by action" New topic
Author

How to know img tag src attribute loaded completely by action

kavin clain
Ranch Hand

Joined: Jan 19, 2010
Posts: 68
In my Javascript I set img tag's src attribute using action:

function setTheater(){
(document.getElementById('codeword0')).src = 'theator.do';
(document.getElementById('codeword1')).src = 'theator.do';
}

Is there any way to make sure that another action do not execute before the first image completely loaded by the first action?
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
What is the first action and the second action?

You probaly want onload and onerror events.



Eric
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I'm curious why you *care* about making them mutually exclusive.
kavin clain
Ranch Hand

Joined: Jan 19, 2010
Posts: 68
Thanks to both of you for your support. With some efforts I solved the problem.


Actually I was calling theator.do action to load img tag.
At the time of streaming the image: the action class saves associated(to image) character in character array.
And the character array is one stored in session.


when my javascript...

...executes one by one, then the associated action classes threads executes in a random fashion.
This caused the skipping of few of the character in the character array.

I solved the problem by invoking consecutive action call when previous img tag is loaded.

Thank you.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Why not just fix the real problem and not store it in session? Why wouldn't you store it in a local variable and stream that?
kavin clain
Ranch Hand

Joined: Jan 19, 2010
Posts: 68
The characters I store in character array is something I want to hide from the user.
I cannot expose it. That is why I saved it in session.

Every thing working fine because now I am calling consecutive actions to access images
only when the previous img tag is loaded using the onload function.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Er, a local variable in a servlet/action *is* hidden from the user, so your explanation makes little sense to me. And "hiding it from the user" makes no sense, since you're displaying the contents of the byte array--it's the image. Whatever.
kavin clain
Ranch Hand

Joined: Jan 19, 2010
Posts: 68
I have two constant arrays... one holds the chars that I want to hide from the user,
and another array for holding the image paths.

I want to show images saved in path-relative-to-the-application.
So get those images & stream those to output. At the same time
save the char associated with the image.

Because the servlet/action thread ends & another action request when made the same thing repeats.
To recognize the user's char-array, save it in session & retrieve on next action request from the user.

I want to show the images & store the associated chars without being noticed by users.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I honestly don't understand what you think you're doing. Nothing on the server side is visible to users unless you deliberately expose it. The image is going to the user: there's no reason to put anything in session; all you need to do is stream the image bytes to the client. Session has nothing to do with that whatsoever. Look at any image-streaming servlet: the session is completely uninvolved. There's no reason to do this synchronously (and reasons *not* to).
kavin clain
Ranch Hand

Joined: Jan 19, 2010
Posts: 68
I think I inappropriately used the word 'hide'.

What I assume I can send one image at a time using a servlet/action.
I want one character associated with the image to store somewhere,
so that I can hold all characters all together in a sequence to use it later for decision making.

I expect a response from user which is based on images.
Then I cross check the response with my stored characters.

The images is like puzzle and characters are like solution.

Action class creates threads for each request from different users.
I store character sequence in session & fetch the one for the user to update it.
I call five requests for five img tags for each user.
The images are stored in WEB-INF sub directory.
Because I can't allow users to see the image path.(Application's need)
In servlet/action I set response.setHeader("Cache-Control", "no-cache");
JavaScript stores image one by one in img.src using action.do.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Oh, you're doing a captcha. I still wouldn't do it like that, but I understand now.
kavin clain
Ranch Hand

Joined: Jan 19, 2010
Posts: 68
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Splitting it up into multiple images will make it even easier for a bot to break it.

Eric
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Hmm, interesting point, especially if it's a fixed number of images.
kavin clain
Ranch Hand

Joined: Jan 19, 2010
Posts: 68
In the actual implementation the the number of images vary between 5 to 8.

Before all images loaded the style:class is visibility:hidden & when all loaded then only the visibility:visible.
When loading I show a preloader.

The character array length is controlled from server & on form submission the characters are cross checked.
If not matched the form will be shown with new image array.

There are hundreds of images which when rendered appears as one image.
The style of the images are one on Yahoo signup page: "images stick to each other & quite shaky".
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
It appears as one image but it is multiple images. All someone has to do is record the images manually and do a comparison. This is not hard to crack.

Eric
 
Don't get me started about those stupid light bulbs.
 
subject: How to know img tag src attribute loaded completely by action
 
Similar Threads
Image as part of HTML email
Servlet returns snippet but image does not appear when run on cell phone
displaying next image on clicking a link
Nested Tag (in Form of Table ) :: not able to submit masterForm
img tag empty src attribute causes duplicate form submission