homepage Welcome to WebmasterWorld Guest from 54.204.231.110
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Strip File Extensions
Javascript to strip last 4 characters?
Revata




msg:3914765
 12:17 am on May 16, 2009 (gmt 0)

I'm building a page with a media player and playlist. On each playlist item i have a 'play' link that fires off a load command and a play command to the player.

I also have a "Now Playing" Div that listens for a new file to start and displays the filename. So it would display, "Now Playing: video.flv" or something like that.

My question is, is there a way to write some Javascript inline that will strip the extension off of the video's file name?

Here's the 'now playing' script:

<script type="text/javascript">
var player = null;

function playerReady(obj)
{
player = gid(obj.id);
displayFirstItem();
};

function itemMonitor(obj)
{
gid('nowplaying').innerHTML = '<span class="style1">Now Playing: ' + player.getPlaylist()[obj.index].file + '</span>';
};

function displayFirstItem()
{
if(player.getPlaylist())
{
itemMonitor({index:0});
player.addControllerListener('ITEM', 'itemMonitor');
}
else
{
setTimeout("displayFirstItem()",100);
}
};

function gid(name)
{
return document.getElementById(name);
};
</script>


 

daveVk




msg:3914796
 2:00 am on May 16, 2009 (gmt 0)

Try

player.getPlaylist()[obj.index].file.split('.')[0]

to display up to first '.'

Revata




msg:3914802
 2:17 am on May 16, 2009 (gmt 0)

Perfect! Works like a charm. Thank you thank you!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved