Solved

How do I avoid caching a image?

Posted on 2000-03-10
12
173 Views
Last Modified: 2010-04-09
Hi,

I would like to put a banner in my page but I don't want it to be cached(by neither proxy nor browser).

How can I do that by "pure" HTML or Javascript?

I don't have a lot of control, although I know an easy way to solve that is to use Server-sided scripts or HTTP headers.
0
Comment
Question by:jthsu
  • 8
  • 2
  • 2
12 Comments
 
LVL 8

Accepted Solution

by:
xabi earned 100 total points
ID: 2603731
Here goes the code.

------- 8< --------- 8< ------
<script languaje="javascript">
<!--
var now = new Date()
document.write("<img name='foo.gif?nocache=" + escape(now) + "' width='200' height='200'>"
//-->
</script>
------- 8< ---------- 8< -------

replace your <image ....> with my code and modify it to your image size and name.

xabi
0
 
LVL 8

Expert Comment

by:xabi
ID: 2603733
It's language, not languaje ... sorry (Typo)

xabi
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 2604779
Yes, and even simpler is:


<script languaje="javascript">
<!-- //
 document.writeln("<img name='myimage.gif?nocache=" + Math.random() + "' width='200' height='200'>" );
// -->
</script>


... that way you don't have to mess with a Date.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 33

Expert Comment

by:knightEknight
ID: 2604783
... and as xabi noted, its "language"  ;)
0
 

Author Comment

by:jthsu
ID: 2605490
I put the following code in my HTML but i did not work...

<a href="http://media.exchange-it.com/click.go?b116995=1" target="_top">
<script language="javascript">
<!--
var now = new Date()
document.write("<img name='http://media.exchange-it.com/image.go?b116995=1?nocache=" + escape(now) + "' width='468' height='60'>"
//-->
</script></a>

I wonder if it's because of double question marks it has within the document.write.
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 2605538
Try this:

document.write("<img src='http://media.exchange-it.com/image.go?b116995=1?nocache=" + escape(now) + "' width='468' height='60'>" );

0
 
LVL 33

Expert Comment

by:knightEknight
ID: 2605539
________________________________________________________________________________________________________________________
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 2605543
... I think the main things were:
1) missing parentheses at the end, and
2) you had "name" instead of "src"
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 2605547
... points should go to xabi, ofcourse
0
 

Author Comment

by:jthsu
ID: 2605600
Hi,

Now I can see the picture. But I still can't avoid the banner being cached.

Any other suggestion?

.....
<a href="http://media.exchange-it.com/click.go?b116995=1" target="_top">
<script language="javascript">
<!--
var now = new Date()
document.write("<img src='http://media.exchange-it.com/image.go?b116995=1?nocache=" + escape(now) + "' width='468' height='60'>");
//-->
</script></a>
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 2605620
Ah, I think I see the problem.
Try this:

<a href="http://media.exchange-it.com/click.go?b116995=1" target="_top">
<script language="javascript">
<!--
document.write("<img src='http://media.exchange-it.com/image.go?b116995=1&nocache=" + Math.random() + "' width='468' height='60'>");
//-->
</script></a>
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 2605625
... the problem being the "?" before "nocache" -- it should have been a "&".
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Create animated movies for web page 18 86
Sort Order Icons on HTML Table 3 35
alert(innerHTML); 8 32
Diminish Pop-up  in 3 seconds 7 49
This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question