Solved

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

Posted on 2008-10-21
9
311 Views
Last Modified: 2008-11-11
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
0
Comment
Question by:Daniish
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 
LVL 7

Expert Comment

by:bluV11t
ID: 22769309
This might help:

hs.captionEval = this.content.src.replace(\'.jpg\', \'\');
//add this line after:
hs.captionEval= hs.captionEval.substr(myString.lastIndexOf('/')+1));
0
 
LVL 82

Expert Comment

by:hielo
ID: 22769333
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

0
 

Author Comment

by:Daniish
ID: 22771654
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?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 82

Expert Comment

by:hielo
ID: 22771859
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

0
 

Author Comment

by:Daniish
ID: 22772151
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.
0
 
LVL 82

Expert Comment

by:hielo
ID: 22772377
>>but please keep trying.
Yeah right. Not in the dark!
0
 
LVL 7

Expert Comment

by:bluV11t
ID: 22775273
Try this:
myString = this.content.src.replace(\'.jpg\', \'\');
//add this line after:
hs.captionEval= hs.captionEval.substr(myString.lastIndexOf('/')+1));
0
 

Author Comment

by:Daniish
ID: 22775586
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
0
 

Accepted Solution

by:
Daniish earned 0 total points
ID: 22897537
The Highslide forum author has provided a working solution:
http://highslide.com/forum/viewtopic.php?t=2580&highlight= 
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

687 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question