Link to home
Start Free TrialLog in
Avatar of Daniish
DaniishFlag for United Kingdom of Great Britain and Northern Ireland

asked on

How is this Javascript extended to replace the domain name etc?

Hello,

I'm using the Javascript thumbnail viewer called Highslide (http://highslide.com/). One of the commands that are available allow an image filename to be added as a image caption.

For example:
      hs.captionEval = 'this.content.src.replace(\'.jpg\', \'\')';

...will remove the '.jpg' from the filename.

Please can some tell me how i can extend this so that the current caption can be changed from:
http://www.globexposure.net/includes/travel_pics/163/Toby Texas%20Chainsaw%20Massacre.jpg
to
Toby Texas Chainsaw Massacre

Please note, however, that the '163' element of the current name is an id variable, and will therefore change between images.


Many thanks for your help
Avatar of bluV11t
bluV11t
Flag of Norway image

This might help:

hs.captionEval = this.content.src.replace(\'.jpg\', \'\');
//add this line after:
hs.captionEval= hs.captionEval.substr(myString.lastIndexOf('/')+1));
Avatar of hielo
try:
var str="http://www.globexposure.net/includes/travel_pics/163/Toby Texas%20Chainsaw%20Massacre.jpg";
var result = str.replace( /.*\/([^\/]+)\.jpg$/i,"$1")
alert( result );

Open in new window

Avatar of Daniish

ASKER

Blu - your code makes the whole caption area under the images, disappear!

Hielo - sorry perhaps i wasn't clear, each image on my site (there will be hundreds) needs to have its filename set to be the caption. Therefore, it is not possible to hardcode the var 'str'.
Is there a way var str could be set dynamically?
the hard-coded value was just an example. What you really need is:



hs.captionEval = 'this.content.src.replace( /.*\/([^\/]+)\.jpg$/i,"$1")';

Open in new window

Avatar of Daniish

ASKER

Hi Hielo,

It looks very complex, but i'm afraid that it doesn't appear to do anything. I can't begin to understand what it does but hopefully you can see what's wrong.

Thanks again but please keep trying.
>>but please keep trying.
Yeah right. Not in the dark!
Try this:
myString = this.content.src.replace(\'.jpg\', \'\');
//add this line after:
hs.captionEval= hs.captionEval.substr(myString.lastIndexOf('/')+1));
Avatar of Daniish

ASKER

Hi Blu - your code seems to hide both the caption and controlbar

You can see the effect here www.globexposure.net/index_blu.php

as opposed to the normal look www.globexposure.net/index.php
ASKER CERTIFIED SOLUTION
Avatar of Daniish
Daniish
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial