Setting The Src Attribute Using Script And Caching Images
Jul 27, 2005
I have noticed that when you set the src attribute of an img via script,
(instead of hard-coding in the img tag), although it caches the images,
if you leave the site and return, the browser has to re-cache the images.
Is that just the way it is, or is there a way to not lose the cache?
i have found a possible bug in 1.4 but it's only in Internet Explorer 7 & 8.The following code does not work and completely ruins every peice of jquery on the page (that means everything inside $(document).ready and anyting else...
I cant see any syntax errors - i pulled the example from the 1.4 site. There is no trailing commas in the object notation and i really cant see any reason it would work in firefox and not IEx and more to the point not only not work in IEx but break any other jquery in the entire page....
I have a function which caches images for a slideshow once the script has loaded. Here is an exerpt:
var base_ref = "http://www.example.com"; var images = new Array(); var tmp_images = new Array(); tmp_images[0] = "image1.jpg"; tmp_images[1] = "image2.jpg"; tmp_images[2] = "image3.jpg"; tmp_images[3] = "image4.jpg"; tmp_images[4] = "image5.jpg";
function cache_images () { for (var i=0; i < tmp_images.length; i++){ var cacheimage=new Image(); var tmp_name = tmp_images[i]; var url = tmp_images[i] + ".png"; cacheimage.src=url; images[tmp_name]=cacheimage; } }
As it is, the script whizzes through the for loop, and then moves on to the next function. The only trouble is that it moves on to the next function whilst it's still downloading the images from the server. Is there anyway to make the script wait until the downloading is completed, so that I can then go on to resize the images if it's needed?
I run a webcam streaming site, and has a gallery of images saved every hour every 24 hours, the thumbnails dont seem to change much (?) so wondered if there was a way to stop caching using a javascript . . . script? This is what im dealing with:
I have a superclass where I create a "div" element as a property and then proceed to try and set the element's "id" attribute in a subclass. Interestingly, if I create multiple instances of the subclass with different "id"s, they all end up having the last "id" I specify. I would like it if they retain the individual "id" I specify. Here is the code.
function Drag() { this.ele = document.createElement("div"); } function Icon(id) { this.ele.id = id; } Icon.prototype = new Drag(); var hello = new Icon("hello"); var goodbye = new Icon("goodbye");
I have <style> tags in my <head> section, and only want to set the cursor attribute if the user's browser has JavaScript enabled. This code however doesn't set the cursor attribute even if JavaScript is enabled:
I am trying to get my script working in FF, IE and Opera but the getAttribute isn't working for me. The domain name isn't getting picked up I have tried this:
This is the Javascript function that I use to hide/show DIV content. I use it everywhere without problems:
[Code]...
However, I get strange behavior when the above DIV is located within an AJAX response. My main page loads another HTML page into a div, and within THAT div is the "div6" above.
So what I am trying to do is make it so that every time the page is opened or refreshed we get a different image with the corresponding link. Of course I can't make this work.
I have the following code:
<script language="JavaScript"> var id = 3; var ranimage = new Array(); var imagelinks= new Array();
I'm trying this to no avail (using the Cycle plugin, the source html DOES have the includes for jQuery and cycle external files): $(function() { $('#slideshow').cycle({ fx:'fade', fit: 1, pause: 1, timeout: 1000, height: 360, width: 550, random: 1, after: function() { $('#pcaption').html(["this.children"][0].attributes[0].childNodes[0].data); }});});
The problem line is: $('#pcaption').html(["this.children"][0].attributes[0].childNodes[0].data); What I am trying is to get the text from the alt attribute to change the <P> after the image.
I've tried: $('#pcaption').html(this.alt); $('#pcaption').html(this.children.alt); And I still can't get the alt text from the image tag. I want to have images with an URL, but I need them to have descriptions (that's why the ALT in each image).
i know that the background attribut on table is not official but you can still use it and it will load an image as a background but i have an already coded site wich uses this background tag and a preload image js function wont work correctly, is there an solution to this?, right now i only see changing the code of the page(it's a damn nasty table based code)
In the doucmentation I'm reading that images in the same gallery need to have the same rel attribute value. But when I do that only the loading animated gif will show on top of the overlay. If I take out the rel then each image will display in a single thickbox. How can I get a gallery of images to display in the thickbox?
If I use javascript to 'read' and XML file does that mean that the XML file gets downloaded to the user's cache?
I'm building a quiz and I'd rather not have the answers too easily available. I believe there's no real way to secure anything client side with javascript so I'm just trying to keep the curious at bay.
I have a oc4j application server hosting my application . I can see from tcp monitor for eg: GET /scripts/main.js and the server responds with last-modified timestamp. However for subsequent request IE does not use if-modified-since and further for each script in Local Settings is getting cached as main[1].js, main[2].js etc and also in different directories. This does not happen for all script but if a page has some 15 scripts included the last 5 scripts show this behaviour.
I had an incident in which I uploaded a swf file with an incorrect URL. Well, when I noticed the issue I uploaded a 'new' file - but those who have previously seen the site kept seeing this "older .swf".Without a huge proces. renaming files, modifying html files etc.. Is there a way to customize a meta tag or some other mechanism to have a '.swf' file NOT CACHE. It has to not cache in all browsers.. ala: ie, ff, safari
I'm working with a large (and unweildy) ASP.NET application, and there is a lot of jQuery code that uses selectors like this:
[name=_aspnetControl$_withASubControl] And unfortunately, some selectors that also look like this:
[name^=_someAspNetControl$_radioButtonList].
In other words, the effort to remove the $ from the attribute selectors would be monumental. If it is possible to escape the $ symbols, I can do that easily enough, but unfortunately the situation right now means that I can't upgrade to jQuery 1.5.
I'm learning jQuery with XML. I'm familiar with other query languages such as XPath. I'm having a little bit of difficulty wrapping my brain around how jQuery works but I think I can make the leap if I see a solution to a problem I know how to solve with other methods Given the following XML, please share a jQuery solution to finding the value of attribute B in elements named bar where attribute A has the value 30:
I'm passing the asp parameters using the url current page is files.asp and I'm using window.location.href=files.asp?action=deletefile to pass the action to the serverside
My code never got executed (like the page was cached) unless i put document.write("") before the window.location directive.
Here's the code:
function confirmDelete(x){ var potvrda=confirm("Kliknite OK za brisanje. Cancel za povratak."); if (potvrda==true) { trans="files.asp?action="+x; document.write("") window.location.href=trans; } else {} }
I've created a page that uses HTTPRequest to include some XML data and allow the user to update that data. The problem is that the new data doesn't show up, even though the XML file is changed.
I can call the XML file up in a separate browser window, where I get the old data, refresh to get the new data, then when I refresh the first browser, the new data appears on the page.
I'm thinking this might be some sort of server caching issue. Has anyone else run into this? Does anyone have a solution?
This example will show that the first call to "doit()" will print 30 times the image with only one call to the server. Then I have a timeout and call doit() again, and this time, it downloads the picture 30 times!!!! It doesn't even time to finish downloading the pictures before the next timeout kicks off and if I let it go for a minute or two i have like 300 calls to download the same image trying to be downloaded!
I heard about a bug in IE that would require to preload the images using a hidden div, but that didn't work. I see that google maps manage to not having to reload the image and gets it from cache. What am I doing wrong? This works perfectly in Firefox (i.e. it uses the cache and calls the server just once). Code:
Can anyone help figure out why my javascript preloaders aren't preloading! Code:
the navigation section utilses simple js rollovers on the text options, with the onMouseRollover event loading an additional graphic image to the right of the menu. It appears almost instantaneously on broadband, but as I'm testing it on 56k and I'm trying to appease all users I required the navigation images to preload (especially those giving the description of the option).
They appear to preload fine in Netscape7 but not in IE6???
I won't list the entire source here apart from the following sections:: Code:
I'll trying to tell the difference between the following three cases:
<img alt="text string" /> <img alt="" /> <img />
I can do this in Firefox with the following code, where elem is the HTMLElement representing each image, but IE doesn't seem to differentiate between empty string and undefined.
var alt = elem.getAttribute('alt'); alt = (alt) ? alt : ((alt===null) ? 'really_null' : "");
The desired output from running this code on the 3 tags above is:
text string
really_null
It seems like this should be really easy...but I'm having a really difficult time trying to figure out what's going on...
We have a dynamically created javascript menu (from ASP), which is customised per user (Have already taken all the static code out into separate cached .js file)
The size of the 'dynamic' menu content can be as much as 10kB, and the menu typically does not change for the duration of the user's session - i.e. it would be nice to get the browser to 'cache' this. It is an Intranet application, and is typically aimed at IE6 clients only.
Have considered the following strategies
1) Cookies - although the last thing I want is the whole menu coming back to the server on every HTTP request - but would be useful IF there is e.g. a header option the cookie to 'send' the cookie (Server -> Browser) without the browser ever sending it back to the server (but the browser still being able to 'read' the cookie?)
2) Creating 'dynamic' javascript files - i.e. send the output per user to a mangled .js file (e.g. with a session ID in the filename), into a cached js file. Would however need to cleanup the files quite regularly, and giving IUSR file creation access doesn't seem a good idea. Would then get the browser to include the JS by generating ASP along the lines of. <script language="JavaScript" src="TempScripts/Menu<%=UserSession%>.js"></script>
Is there any other way?
Second Question : Is there any way to get IE to stop sending up the HTTP REFERER header up to the server (e.g. RegKey) - this is pretty pointless on an Intranet App (I know there is a way to do in NetScape).