If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

how to extract img src from an external list

Greetings

I need your help please..
I have a website of 20 pages. Each page displays an image from a catalog located in another domain, and the catalog changes each week, so I have to change the img src attribute each week too (the jpg images are named differently each week, though in the same directory). So instead of editing 20 html pages each time, I'm trying to find a way to control the img src from a text file, so that I edit only that text file once a week.

Is there a way to extract img src attributes from a text file or js file please?
For example I need page 1 to extract the first img src listed in the text file, and page 2 to extract the second src listed, etc.
I'm new to js so please give an example of the code that I should use.

// A Javascript file name myImg-38.js (38 is the ISOWeekNumber)
// An array of image src
var arrImg="img0.jpg,img1.jpg,...,img19.jpg".split(',');

Your pages

Code:

<script type="text/javascript">
Date.prototype.getISOWeek = function() {var i,d,firstWeekMonday;
var i=1;while (new Date(this.getFullYear(),0,i).getDay()!=4) ++i;// i the first Thursday;
var firstWeekMonday = new Date(this.getFullYear(),0,i-3,0,0,0,-1);// one millisecond before
d=Math.ceil(((this-firstWeekMonday)/60000-this.getTimezoneOffset()+firstWeekMonday.getTimezoneOffset())/(1440*7));
if (d==53 && new Date(this.getFullYear(),0,1).getDay()!=4 && new Date(this.getFullYear()+1,0,0).getDay()!=4) d=1;
return d?d:new Date(this.getFullYear(),0,0).getISOWeek();// the week of the 31 December before if d is null !
}
var tdy=new Date(),isoNumber=tdy.getISOWeek(),jsFileName='myImg-'+isoNumber+'.js';
// A simple method to load the scipt with the opening of the page
document.write('<script type="text/javascript" src="+jsFileName+"></script>');
// then the array arrImg is available
</script>

An other method could consists to load dynamically the script like on this page

@007Julien
Thanks very much for the script. What does it do? I find it hard to understand..

@ZABI
Many thanks for the simple script, it worked like a charm.
You mentioned earlier that if I used php I will not have to update any files? that would be very much interesting. You mean a script that extracts the image links from the source directly?
Can you please write me an example of such fascinating script?
(btw: the number of images vary each week, sometimes 16, 20, 24..)
the img src links look like this:

The proposed script create a new method to the object Date to get the ISO week Number. Then you have only to define many javascript files (one a week : myImg-0.js, myImg-1.js, myImg-2.js ...) to describe the images...

NB : It 's not necessary to repeat the full path in the array of images !

well the PHP method will require PHP installed on your server (mostly shared hosting servers have already). Plz also send me the link from where you want images to get, actually the idea is to parse the page and extract images' src from it, then you can show those images where you want.

Many Thanks ZABI. I've tested the script and when loaded in the browser it outputs all 20 links. But there is a part that shouldn't be in the URLs, which is: "Photo_"

../ContentPhotos/Photos/Photo_Spinneys flyer0-1_012829.jpg

And since those are relative links, can you change the first script to use relative links instead of absolute links?
I'm supposed to use the php file instead of the js file, right?
But then, if I used a cron tab to execute the php file each week, can you make the php file write the output into a text file (or a js file like the first one?), so that the pages use img src links from there? or do you mean that the html pages will execute the php file and get the im src from there directly?

Please re-write the script that I should insert in the html pages to use your new php script, so that I understand better what to do.