473,396 Members | 1,683 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,396 software developers and data experts.

Javascript - lastModifed

Hi,
I have a web page with links to external files and I would like to include the date the external file was last modified in the href description. Our servers don't seem to support SSI or PHP.

Any ideas how to do it? It feels as though it should be fairly simple but I can't find anything on the web.

Cheers

Doug
Oct 11 '07 #1
2 1211
epots9
1,351 Expert 1GB
Hi,
I have a web page with links to external files and I would like to include the date the external file was last modified in the href description. Our servers don't seem to support SSI or PHP.

Any ideas how to do it? It feels as though it should be fairly simple but I can't find anything on the web.

Cheers

Doug
jaascript is client side scripting and it can't read/write to files...unless you use ajax.
Oct 11 '07 #2
mrhoo
428 256MB
Using javascript is an expensive way to do this- and it only works for files on the same domain as the page with the links.

Much better to write a script on the server that will rewrite the html page
when you modify one of its linked files.

This script will add the modified date of a link to its title the first time you hover or focus it-
You can modify it to write all the modified dates into the link text in the onload handler,
but this really belongs in a server routine.
Expand|Select|Wrap|Line Numbers
  1.  
  2. function titleModified(who){
  3.     var aj= AJX(); // http request object, defined below (or use your own)
  4.     var url, t;
  5.     who= window.event? event.srcElement: who.target;
  6.     url= who.href;
  7.     t= who.title || '';
  8.     try {
  9.         aj.open("HEAD", url, false);
  10.         aj.send(null);
  11.         if (aj.status== 200) tem= aj.getResponseHeader('Last-Modified');
  12.         else tem= '';
  13.     }
  14.     catch (er) {
  15.         tem= '';
  16.     }
  17.     if(tem) who.title= t+' Last modified:'+tem;
  18.     who.onmouseover= ''; // don't call again for this element
  19.     who.onfocus= '';
  20. }
  21.  
  22. function AJX(){
  23.     var obj;
  24.     if (window.XMLHttpRequest) return new XMLHttpRequest();
  25.     else if (window.ActiveXObject){
  26.         try{
  27.             obj= new ActiveXObject('MSXML2.XMLHTTP.3.0');
  28.         }
  29.         catch(er){
  30.             try{
  31.                 obj= new ActiveXObject("Microsoft.XMLHTTP");
  32.             }
  33.             catch(er){
  34.                 obj= false;
  35.             }
  36.         }
  37.     }
  38.     return obj;
  39. }
  40.  
  41.  
  42. window.onload= function(){
  43.     if(!AJX()) return false;
  44.     var cnt= 0, who,tem, A= document.getElementsByTagName('a');
  45.     while(A[cnt]){
  46.         who= A[cnt];
  47.         tem= who.href;
  48. //next line to skip page bookmarks
  49.         if(tem && !/^#/.test(tem) && tem.indexOf(location.pathname)== -1){         
  50.             who.onmouseover= titleModified;
  51.             who.onfocus= titleModified;
  52.         }
  53.         ++cnt;
  54.     }
  55. }
Oct 11 '07 #3

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

Similar topics

0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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
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...
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.