Forum Moderators: open

Message Too Old, No Replies

Taking info from the URL in the adress

Java script for a special function.

         

Marz5

10:53 am on Aug 22, 2006 (gmt 0)

10+ Year Member



I have a photo gallery that with thumbnails. When clicking upon thumb, a new window with the enlarge image comes. The filename of this window is always in the format:

www.maltawildplants.com/NAME/Pics/CODE2/F/FT01.html

Now I need some java script to extract info from the image window url address to be placed (generated) automatically as a pic code in the html file itself. It is impossible to do this manually for my 2200 pic collection.

The file structure is always as /NAME/Pics/AAAAA/F/FT##.html so what I need is to grab AAAAA an FT## so they are used in the html to show say:

Photo code: "AAAAA-FT##" or AAAAA##

Then with a smart find/replace strategy of whole folder of my site I can hopefully include the jaca script, for example at the end of the file, under each image.

eg:

Replace "<!-- end of file ->"

with

"Photo Code number is : <java script> ...coding... </script>
<!-- end of file ->"

RonPK

11:39 am on Aug 22, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That shouldn't be too hard. You can use a regular expression to extract the desired info from the URL.

var pieces = location.pathname.match(/^\/NAME\/Pics\/(.*?)\/F\/FT(.*?)\.html$/); 
document.write('Photo code number is: ' + pieces[1] + '-' + pieces[2]);