473,406 Members | 2,698 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.

Loading images in the background

Hello everyone ;)

I would like to load some images using JS.

My code:
Expand|Select|Wrap|Line Numbers
  1. var img=new Image();
  2. img.onload = function() {f1()};
  3. img.onerror = function() {f2()};
  4. img.src='http://example.com/image.gif';
  5. sett = setTimeout(function() {f3()}, 100000);
  6.  
  7. //f3 contains not interesting code and:
  8. img = null;
  9. clearTimeout(sett);
  10.  
Simply task, but I have two problems.

1) Some images don't listen to orders from setTimeout and load for 200 and more second. What is wrong with my code? Notice, that it happens only with some images, not all.

2) Images are loading according to status of currently user. In some cases there can appear images which require to login by htpassword to see them. Then user would see a window with fields to login. What can I do to in that case skip this image and avoid showing that window?

Thank you so much for any help.
Aug 20 '10 #1
4 1779
gits
5,390 Expert Mod 4TB
1) what do you mean with 'orders from setTimeout' exactly?

2) i would say that you would need to handle that serverside - the client don't know - and shouldn't know - what the user is allowed to do. the serverside could request the photo from a directory and check the users permission - when it is a forbidden picture - just proceed to try to read the next one.
Aug 22 '10 #2
Thank you so much for answer

1) Never mind. I changed some things and it works perfectly.

2) I can't do it server-side - that's the point. However, server does know which images are available for current user. If he request wrong image he gets 401 error. Privileges are given dynamicly, are diffrent according to user status, actual time etc. It must be JS.
Aug 23 '10 #3
gits
5,390 Expert Mod 4TB
when implementing security critical things clientside with JavaScript you would need to be aware that this could easily be tricked by medium skilled users - so in case it would be 'mission critical' you couldn't rely on such an implementation.
Aug 24 '10 #4
Images are protected by 401 Error - user can't access them manipulating JS.

My site is dynamicly changing, sets of images are changing during visit. My script is too complicated to be always right. Sometimes there can be a bug - requesting wrong image.

Is there any way to ignore these images and go to next?

(Be sure that I made all my best to solve this problem by another solution - this is my last chance)
Aug 27 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Nick | last post by:
How to change the pic to a "show error" image when loading images failed - for example, no image file exists? I tried to add the following statement in the onload event function: if...
3
by: John Ortt | last post by:
Hi everyone, I posted with the title "Javascript Menu Not Loading Images" last week but I only posted the code as the site was on a corporate Intranet. Thanks to advice on the thread I have...
9
by: josvanr | last post by:
HI I'm working on a site http://www.josvanriswick.nl/nieuw in which i use absolute positioning. On my pc at home i didn't notice, but now, as the site is on air and loading images is a bit...
10
by: windandwaves | last post by:
Hi I have the following html: <div id="menu"> <div id="m1"><a href="m1.php"><img src="m1.gif" alt="m1"></a></div> <div id="m2"><a href="m2.php"><img src="m2.gif" alt="m2"></a></div> <div...
15
by: Geoff Cox | last post by:
Hello I have following type of code in the header function pre_load_pics() { if (document.images) { var image1 = new Image(400,265); image1.scr = "pic1.jpg";
2
by: John | last post by:
Hi all, I'm having a problem loading images for later use in javascript on the client. In my code-behind, I'm using a stringbuilder object to build and populate a few javascript variables like :...
4
by: VR | last post by:
Hi, I am trying to have a menu item (which is an HTML img) to change as a mouse moves over it. So, my code looks something like this: <a onmouseover="ActivateImage('MyImage');"...
6
by: Ivan Bútora | last post by:
I have recently looked at http://alistapart.com/articles/imagegallery to implement a simple picture gallery on a webpage that I'm working on. Everything works fine; however, I have one question....
1
by: mlikesit | last post by:
I am trying to get the following code to pre-load some images before re-dirrecting the user. The problem is that the onError event gets called for all of the images immediately. I've tripple...
2
by: obstinate | last post by:
hello all, i'm a newbie in ajax. now i work in team that developed an online map site which is similar like google map. we use <div> to contain the map. This div contains map image tiles and...
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:
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...
0
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...
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.