yanjchan Posted December 19, 2009 Share Posted December 19, 2009 I'm trying to get this JQuery sound plugin to play a sound. I have managed to make it work in onClick and onLoad events... but no luck in actualy javascript code. I don't get at all why it won't work, it just seems to skip paste. function insertNewContent(liTime,liName,liText) { insertO = document.getElementById("outputList"); oLi = document.createElement('li'); oSpan = document.createElement('span'); oSpan.setAttribute('className','name'); //for IE's sake oSpan.setAttribute('class','name'); oName = document.createTextNode('At '+liTime+', '+liName); oText = document.createTextNode(liText); oSpan.appendChild(oName); oLi.appendChild(oSpan); oLi.appendChild(oText); insertO.insertBefore(oLi, insertO.firstChild); document.title = liName+" says..."; $.sound.play('/sounds/pop.wav');</script> } The library I am using is here: http://www.google.com/url?sa=D&q=http://dev.jquery.com/view/trunk/plugins/sound/&usg=AFQjCNGFOlQdzQaPRwqMSuIVCUFPIFGhCQ By the way, this is part of an AJAX chat thing. You can ignore the beginning part, just know that this is being executed at the end of the insertion. (or, rather, it should be.) Quote Link to comment Share on other sites More sharing options...
monkeytooth Posted December 19, 2009 Share Posted December 19, 2009 Im not a javascript expert or anything. but where you have "</script>" before the } could that be effecting it? Quote Link to comment Share on other sites More sharing options...
yanjchan Posted December 19, 2009 Author Share Posted December 19, 2009 eh heh... good catch. I'll try again, and report back. Quote Link to comment Share on other sites More sharing options...
yanjchan Posted December 19, 2009 Author Share Posted December 19, 2009 Sorry for the ugly code, but I've gotten this... strangely, it isn't working. //inserts the new content into the page function insertNewContent(liTime,liName,liText) { insertO = document.getElementById("outputList"); oDiv = document.createElement('div'); oScript = document.createElement('script'); oLi = document.createElement('li'); oSpan = document.createElement('span'); oSpan.setAttribute('className','name'); //for IE's sake oSpan.setAttribute('class','name'); oName = document.createTextNode('at '+liTime+', '+liName+' said'); oText = document.createTextNode(liText); if (stristr(liText, document.forms['chatForm'].elements['name'].value)) { oDiv.setAttribute('style','font-size:200%;'); } oScript.setAttribute('type','text/javascript'); oScriptText = document.createTextNode('$.sound.play(sounds/pop.mp3)'); oLi.appendChild(oScript); oScript.appendChild(oScriptText); oLi.appendChild(oSpan); oSpan.appendChild(oName); oLi.appendChild(oDiv); oDiv.appendChild(oText); insertO.insertBefore(oLi, insertO.firstChild); } I'm new to AJAX, so pardon my messiness. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.