Welcome to WebmasterWorld Guest from 54.198.185.204

Forum Moderators: open

Message Too Old, No Replies

URL Decoding

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

New User

5+ Year Member

joined:Apr 30, 2009
posts: 30
votes: 0


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?

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

Senior Member from US 

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

joined:Oct 17, 2005
posts:4987
votes: 12


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

Does that work?

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

New User

5+ Year Member

joined:Apr 30, 2009
posts: 30
votes: 0


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 ?

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

Senior Member from US 

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

joined:Oct 17, 2005
posts:4987
votes: 12


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;
}
8:09 pm on Nov 19, 2009 (gmt 0)

New User

5+ Year Member

joined:Apr 30, 2009
posts:30
votes: 0


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