0

I want to split the filename and get the last path of the string in javascript.

For example the path is D://Smita//GMAP//Images//images.jpg , but according to my requirement it should be Images/images.jpg How to acheive this using javascript?

Vinay
  • 6,891
  • 4
  • 32
  • 50

1 Answers1

2

split, slice and join:

var path = 'D://Smita//GMAP//Images//images.jpg'.split('//').slice(-2).join('/');
//path is "Images/images.jpg"

For a Google Maps info window you should be able to throw it as the src of an img element:

content: '<img src="'+path+'">'

See related How to add an image to InfoWindow of marker in google maps v3?

Community
  • 1
  • 1
Fabrício Matté
  • 69,329
  • 26
  • 129
  • 166
  • can u help me how to display image in google map infowindow. From database i am geeting the path as D://Smita//GMAP//Images//images.jpg but no image is displayed rather path is displaying – user1749062 May 18 '13 at 07:07
  • @user1749062 I believe you can just put it as the `src` of an `` tag, see http://stackoverflow.com/a/10161077/1331430 – Fabrício Matté May 18 '13 at 07:11