Welcome to WebmasterWorld Guest from 54.196.212.62

Forum Moderators: open

Message Too Old, No Replies

Strip File Extensions

Javascript to strip last 4 characters?

     

Revata

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

5+ Year Member



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

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

WebmasterWorld Senior Member 5+ Year Member



Try

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

to display up to first '.'

Revata

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

5+ Year Member



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

Featured Threads

Hot Threads This Week

Hot Threads This Month