?
Solved

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

Posted on 2008-10-21
9
Medium Priority
?
313 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
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…
Suggested Courses

770 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