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

Using Javascript to loop images??

Let's say I have a Javascript function that loops over and over. In
that function i have it alternating images on a button this way:

if(var==0){
var myHTML = "<input type='button' style='background-image:
url(grnbutt.jpg);etc. etc.'>";
var outq = document.getElementById("qbutt");
outq.innerHTML = myHTML;
}
else{
var myHTML = "<input type='button' style='background-image:
url(grnbuttdark.jpg);etc. etc.'>";
var outq = document.getElementById("qbutt");
outq.innerHTML = myHTML;
}

This works great using Firefox, and works with Internet Explorer also
EXCEPT if its set to "Check for newer versions of stored pages: Every
visit to the page". With that setting, IE will download those 2 images
from the server every single time through the loop. So then I tried
putting both images on the same jpg and then moving the image:

if(var==0){
var elem = document.getElementById("grn");
elem.style.backgroundPosition = "-100px 0";
}
else{
var elem = document.getElementById("grn");
elem.style.backgroundPosition = "center";
}

This also works, but also, constantly downloads new images when using
IE with the above setting. Microsoft calls this a "feature". They then
offer a fix for this "feature" that... doesn't work. Preloading
doesn't work. Loading the 2 images in a <divset to invisible doesn't
work. I've tried suggestions of creating php files that tell the
browser that the images don't expire for years. That didn't work for
me. Many people have also suggested that there is no way around it...
it can't be fixed until Microsoft fixes it.

So, is there any javascript way to loop 2 images on a button, without
Internet Explorer constantly downloading those 2 images over and over,
when its set to "Check for newer versions of stored pages: Every visit
to the page"??

Apr 17 '07 #1
2 3524
On Apr 17, 7:29 pm, OBAFGKM_...@yahoo.com wrote:
Let's say I have a Javascript function that loops over and over. In
that function i have it alternating images on a button this way:

if(var==0){
var myHTML = "<input type='button' style='background-image:
url(grnbutt.jpg);etc. etc.'>";
var outq = document.getElementById("qbutt");
outq.innerHTML = myHTML;
}
else{
var myHTML = "<input type='button' style='background-image:
url(grnbuttdark.jpg);etc. etc.'>";
var outq = document.getElementById("qbutt");
outq.innerHTML = myHTML;
}

This works great using Firefox, and works with Internet Explorer also
EXCEPT if its set to "Check for newer versions of stored pages: Every
visit to the page". With that setting, IE will download those 2 images
from the server every single time through the loop. So then I tried
putting both images on the same jpg and then moving the image:

if(var==0){
var elem = document.getElementById("grn");
elem.style.backgroundPosition = "-100px 0";
}
else{
var elem = document.getElementById("grn");
elem.style.backgroundPosition = "center";
}

This also works, but also, constantly downloads new images when using
IE with the above setting. Microsoft calls this a "feature". They then
offer a fix for this "feature" that... doesn't work. Preloading
doesn't work. Loading the 2 images in a <divset to invisible doesn't
work. I've tried suggestions of creating php files that tell the
browser that the images don't expire for years. That didn't work for
me. Many people have also suggested that there is no way around it...
it can't be fixed until Microsoft fixes it.

So, is there any javascript way to loop 2 images on a button, without
Internet Explorer constantly downloading those 2 images over and over,
when its set to "Check for newer versions of stored pages: Every visit
to the page"??
Did you try putting the image in the div, and setting its src argument
to the specified string, having preloaded them before that?
Thinking clearly, however, it makes perfect sense if that doesn't
work, since that exactly was the whole point - they made a feature
that checks for newer versions every time, and now you want to
override this feature - thus directly opposing the user's will -
that's not good design. The user's the boss, not you.

However, the above solution (not setting css, but having x = new
Image( "..." ), then later saying
document.getElementById( "image1" ).src = "...", might work, at least
it's worth a shot?

Apr 17 '07 #2
Thanks Darko. I will try to figure out what you wrote, but I am too
burned out at the moment to try it. However, the Internet Explorer
issue is this: Its supposed to check for a new page on every visit to
that page, NOT download the same image over and over again on the same
page without it being refreshed or revisited. I have no problem with
it downloading fresh images on each visit to the page (which is what
its supposed to do). Its a known bug that has many attempted
solutions. None, so far, have worked.

On Apr 17, 2:34 pm, Darko <darko.maksimo...@gmail.comwrote:
On Apr 17, 7:29 pm, OBAFGKM_...@yahoo.com wrote:
Let's say I have a Javascript function that loops over and over. In
that function i have it alternating images on a button this way:
if(var==0){
var myHTML = "<input type='button' style='background-image:
url(grnbutt.jpg);etc. etc.'>";
var outq = document.getElementById("qbutt");
outq.innerHTML = myHTML;
}
else{
var myHTML = "<input type='button' style='background-image:
url(grnbuttdark.jpg);etc. etc.'>";
var outq = document.getElementById("qbutt");
outq.innerHTML = myHTML;
}
This works great using Firefox, and works with Internet Explorer also
EXCEPT if its set to "Check for newer versions of stored pages: Every
visit to the page". With that setting, IE will download those 2 images
from the server every single time through the loop. So then I tried
putting both images on the same jpg and then moving the image:
if(var==0){
var elem = document.getElementById("grn");
elem.style.backgroundPosition = "-100px 0";
}
else{
var elem = document.getElementById("grn");
elem.style.backgroundPosition = "center";
}
This also works, but also, constantly downloads new images when using
IE with the above setting. Microsoft calls this a "feature". They then
offer a fix for this "feature" that... doesn't work. Preloading
doesn't work. Loading the 2 images in a <divset to invisible doesn't
work. I've tried suggestions of creating php files that tell the
browser that the images don't expire for years. That didn't work for
me. Many people have also suggested that there is no way around it...
it can't be fixed until Microsoft fixes it.
So, is there any javascript way to loop 2 images on a button, without
Internet Explorer constantly downloading those 2 images over and over,
when its set to "Check for newer versions of stored pages: Every visit
to the page"??

Did you try putting the image in the div, and setting its src argument
to the specified string, having preloaded them before that?
Thinking clearly, however, it makes perfect sense if that doesn't
work, since that exactly was the whole point - they made a feature
that checks for newer versions every time, and now you want to
override this feature - thus directly opposing the user's will -
that's not good design. The user's the boss, not you.

However, the above solution (not setting css, but having x = new
Image( "..." ), then later saying
document.getElementById( "image1" ).src = "...", might work, at least
it's worth a shot?

Apr 17 '07 #3

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

Similar topics

1
by: Christopher Brandsdal | last post by:
Hi! I have a menu-system in JavaScript. The menu is displayed by two js functions ( DrawMenuBar and DrawSubMenu ). the first function displays the parent items, and includes the other...
0
by: David | last post by:
Please help. I am able to display a folder structure and files but I can't figure out how to add subfolders and maintain the same look. I am a little embarrased but I thought someone out there...
2
by: Rebecca | last post by:
Hello everybody, Since a few years I'm fooling around a little bit trýing to make a website for my husbands' oldmobils. One of the idea's is to let a car 'drive' through the screen, make it 'drive...
2
by: Scamjunk | last post by:
I have been desperately looking for a treeview-type solution for my problem for the past three weeks and have been greatly unsuccessful. I am totally new to the world of XSLT and I *don't know*...
8
by: Yourself | last post by:
Is there anyway of disabling images in javascript, so that the alternative text appears instead of the images? I'm trying to do a text-only version of my site.
7
by: windsorben | last post by:
Why do my images dissappear after I clik on them? Otherwise, the text to speech is working just fine. However, it is not functional if the images dissappear. <script language="JavaScript"...
1
by: viceyo | last post by:
Hi! I'm new to Javascript and I'm trying to write a script in which I need to use diferent variable names. The names are used from here: <img border="0" alt="Visit W3Schools!"...
2
by: phpentrylevel | last post by:
hello i am a newbie to Javascript with a in depth background of PHP i have a simple script that replaces missing images when the webpage loads but i just cant get it to validate in JLint as my...
2
by: swethak | last post by:
Hi, I am developing the google application. In my google.js file consists the icon1=new GIcon(); icon1.image = "images/bmw-small.png"; icon1.shadow = "images/shadow50.png";...
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: 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
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
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,...
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
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...
0
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,...

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.