<div> Tags And Hiding/showing Them

admin

Administrator
Staff member
Hey all<br /><br />I have been working a script for my forum which allows me to use an IFRAME within a DIV tag which can be hidden or shown upon pressing an appropriate button.<br /><br />I.e.. if you press "show frame" the iframe pops up<br />if you press "hide frame" the iframe gets hidden<br /><br /><br />i have managed that successfully using javascript and a few lines of code too<br /><br />however, within my iframe is an MP3 streaming website... so when the iframe is shown the streaming commences and you can hear the song playing<br /><br />in firefox when the iframe is hidden the streaming stops<br /><br /><br />however in IE this is not the case... even though the div containing the iframe is hidden the content continues to be played.<br /><br />i really wanted it to work so that when the iframe was hidden the content didnt play and when it was opened the content did play....<br /><br />Does anyone know how I can do this....<br /><br />I have pasted the .js file and the code i have used below (please forgive my terrible html and javascript coding)<br /><br />The code:<br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--><script type="text/javascript" language="JavaScript" src=http://www.totalchoicehosting.com/forums/lofiversion/index.php/"http://www.*******.com/sclickscript.js"></script><br /><br /><form><center><br /><input type="button" onClick="ShowTrackHi('sclickwindowhi')" value="Play Hifi"><br /><input type="button" onClick="CloseTrackHi('sclickwindowhi')" value="Stop Hifi"><br /><input type="button" onClick="ShowTrackLo('sclickwindowlo')" value="Play Lofi"><br /><input type="button" onClick="CloseTrackLo('sclickwindowlo')" value="Stop Lofi"><br /></center></form><br /><br /><div id="sclickwindowhi" align="center" style="display: none;"><br /><iframe id="hifiplay" style="border:0px solid black" width=500 height=365 <br />src=http://www.totalchoicehosting.com/forums/lofiversion/index.php/"http://www.*****.com/single_player.cfm?songid=******&cache=******&q=hi"></iframe><br /></div><br /><br /><div id="sclickwindowlo" align="center" style="display: none;">    <br /><iframe id="lofiplay" style="border:0px solid black" width=500 height=365 <br />src=http://www.totalchoicehosting.com/forums/lofiversion/index.php/"http://www.*****.com/single_player.cfm?songid=******>&cache=******&q=lo"></iframe><br /></div><!--c2--></div><!--ec2--><br /><br />The javascript file:<br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->function ShowTrackHi(tid1) <br />{     <br />    document.getElementById(tid1).style.display = "";<br /><br />    <br />}<br /><br />function CloseTrackHi(tid1) <br />{ <br />    document.getElementById(tid1).style.display = "none";<br />    <br />        <br />}<br /><br />function ShowTrackLo(tid1) <br />{ <br />    document.getElementById(tid1).style.display = "";<br />    <br />}<br /><br />function CloseTrackLo(tid1) <br />{ <br />    document.getElementById(tid1).style.display = "none";<br />    <br />}<!--c2--></div><!--ec2--><br /><br /><br />All the streaming works correctly, the iframe shows up and disappears fine, its just in IE the mp3 continues to stream even when the iframe is hidden... can anyone suggest how to overcome this?<br /><br />Cheers,<br />OJB<!--content-->
That could be because of the way IE handles web standards. It doesn't.<!--content-->
yea IE is a bit of a pest hahah<br /><br /><br />Well, my brother is a web developer so i recruited him to the cause and he has fixed the problem for me, by basically approaching it from a different angle<br /><br />All seems to be working now but i appreciate you taking the time for me bruce<!--content-->
Could you explain OJB how your brother went about doing this from another angle, there may be other customers wanting to know how it was done?<br /><br />Many thanks<br /><br />JimE<!--content-->
sure...<br /><br />Well my approach was to preload the div tags with the iframe content, but this caused issues because I could not get the content to stop playing. I then came across the div .innerHTML function i suppose where you can modify the contents of the div when you want... however using my method above plus this innerHTML (to fill the div with nothing, i.e. get the content to stop playing) As i had preloaded all the content the div would remain empty once I had used innerhtml to fill it with nothing <br /><br />[really sorry if i am explaining this poorly]<br /><br />anyway, my brother decided not to preload any of the iframe stuff into the div, instead he decided that upon calling the PlayHiTrack and PlayLoTrack functions he would use the innerhtml to fill the div with the IFRAME when the function was called. <br /><br />So essentially everytime the button to play was clicked, using innerHTML the div tags were filled with the iframe and hence the content would commence playing (please note the div was also unhidden upon clicking the play button)<br /><br />Then the close button did what i mentioned earlier it flushed out the div tag by filling it with nothing, this cause the content to stop playing and the div was hidden<br /><br />I can paste the code if this is helpful to people? Sorry if i explained this terribly haha<br /><br />The main code:<br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--><script language="JavaScript" type="text/javascript" src=http://www.totalchoicehosting.com/forums/lofiversion/index.php/"sclickscript.js"><br /></script><br /><form name ="frmsclick"><br /><center><br /><input type="button" value="Play Hi-Fi" name="hifi" onClick="playAudioHi(******)"><br /><input type="button" value="Play Lo-Fi" name="lofi" onClick="playAudioLo(******)"><br /><input type="button" value="Stop Audio" name="Stop" onClick="stopAudio(******)"><br /></form><br /></center><br /><br /><div id="******" align="center" style="display: none;"></div><!--c2--></div><!--ec2--><br /><br />the javascript<br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->/*Music player JS for embedding specific tracks + info. Code by Hygor*/ <br /><br />var passVar;<br /><br />function playAudioHi(passVar){<br />    document.getElementById(passVar).style.display = "";<br />    document.getElementById(passVar).innerHTML ="<iframe style=\"border:0px solid black\" width=500 height=365 "+<br />    "src=http://www.totalchoicehosting.com/forums/lofiversion/index.php/\"http://www.******.com/single_player.cfm?songid=" + passVar + "&cache=******&q=hi\"></iframe>";<br />}<br /><br />function playAudioLo(passVar){<br />    document.getElementById(passVar).style.display = "";<br />    document.getElementById(passVar).innerHTML ="<iframe style=\"border:0px solid black\" width=500 height=365 "+<br />    "src=http://www.totalchoicehosting.com/forums/lofiversion/index.php/\"http://www.******.com/single_player.cfm?songid=" + passVar + "&cache=******&q=lo\"></iframe>";<br />}<br /><br />function stopAudio(passVar){<br />    document.getElementById(passVar).style.display = "none";<br />    document.getElementById(passVar).innerHTML =    "";<br />}<!--c2--></div><!--ec2--><!--content-->
Thanks for they update and glad you found a solution that worked for you.<!--content-->
Thanks for the update, its always good to learn something new<br /><br />Hopefully this may help other users in the future<br /><br />JimE<!--content-->
 
Top