Welcome to WebmasterWorld Guest from 54.226.189.112

Forum Moderators: open

Message Too Old, No Replies

URL Decoding

     

Revata

12:35 am on Nov 12, 2009 (gmt 0)

5+ Year Member



My Javascript isn't very strong, but I've got an event listener that will show a filename when a media file is selected. The script looks like this:


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

...because some of the files have urlencoded filenames I want them to appear without the %27's and such, so I tried this:


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

But since it's expecting a string in the unescape argument it doesnt work. Is there any way I can change the command so that it'll urldecode the filename rather than the word "file" in this case?

Fotiman

2:06 pm on Nov 13, 2009 (gmt 0)

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



player.getPlaylist()[obj.index]._utf8_decode(unescape(file.split('/')[1].split('.')[0])) + '</span>';

Does that work?

Revata

6:14 pm on Nov 19, 2009 (gmt 0)

5+ Year Member



Hm, that didn't work. In fact, entering "_utf8_decode(unescape())" in the command breaks the entire innerHTML. It doesnt even display "Now Playing: ".

I wonder is there any other way to decode other than with: _utf8_decode ?

Fotiman

7:09 pm on Nov 19, 2009 (gmt 0)

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



How about this?


function itemMonitor(obj) {
var str = '<span class="style1">Now Playing: ',
filename = player.getPlaylist()[obj.index].file.split('/')[1].split('.')[0];
filename = unescape(filename);
str += filename + '</span>';
gid('nowplaying').innerHTML = str;
}

Revata

8:09 pm on Nov 19, 2009 (gmt 0)

5+ Year Member



Success! That works, thanks for the help Fotiman. =)
 

Featured Threads

Hot Threads This Week

Hot Threads This Month