Err Posted September 9, 2007 Share Posted September 9, 2007 Hey all.I'm having some JavaScript troubles. I've made a web page where a visitor has to have Firefox in order to see a music player on the page. I've also added in some things for people who have JavaScript disabled. My problem is that I can't add more code in the IF statement in the JavaScript without it messing up in Firefox. Here's the code: <style type="text/css">#player { display: none;}#js { display: block; font-weight: bold;}#ff { display: none; font-weight: bold;}</style><div id="player">You are seeing the player.</div><div id="js">Enable your JavaScript to see the music player.</div><div id="ff">Get Mozilla Firefox to see the music player.</div><script type="text/javascript">if (navigator.userAgent.indexOf("Firefox")!=-1) { document.getElementById('player').style.display = "block"; document.getElementById('ff').style.display = "none";}else document.getElementById('player').style.display = "none"; document.getElementById('js').style.display = "none"; document.getElementById('ff').style.display = "block";</script> Now, I can get the page working right if I separate the code in the IF statement to another <script> block. But I want to keep it all in one <script> block. Can you guys please look at my JavaScript and see if y'all see any wrong with it? I've tested this code out with Opera and IE and it seems like it's just Firefox that doesn't like my JavaScript.Check out the problem web page here:[removed] Link to comment Share on other sites More sharing options...
Jesdisciple Posted September 10, 2007 Share Posted September 10, 2007 To me, it looks like you just need brackets after the else: <script type="text/javascript">if (navigator.userAgent.indexOf("Firefox")!=-1) {document.getElementById('player').style.display = "block";document.getElementById('ff').style.display = "none";}else{document.getElementById('player').style.display = "none";document.getElementById('js').style.display = "none";document.getElementById('ff').style.display = "block";}</script> Without those, the else only applies to the first line immediately following it. The other brwosers took it fine because FF was the only one at the end of an accidentally open block. Link to comment Share on other sites More sharing options...
Err Posted September 10, 2007 Author Share Posted September 10, 2007 I put brackets around the else statements and ordered the statements differently, but that didn't change a thing.Edit: I got it. I had to add the js statement in the IF code also. Here's the working code: <script type="text/javascript">if (navigator.userAgent.indexOf("Firefox")!=-1) { document.getElementById('player').style.display = "block"; document.getElementById('ff').style.display = "none"; document.getElementById('js').style.display = "none";}else { document.getElementById('player').style.display = "none"; document.getElementById('ff').style.display = "block"; document.getElementById('js').style.display = "none";}</script> Link to comment Share on other sites More sharing options...
Jesdisciple Posted September 10, 2007 Share Posted September 10, 2007 Umm... If you're seeing the page not work in Firefox on your end, this will probably frustrate you, but I see both pages only displaying "You are seeing the player." Link to comment Share on other sites More sharing options...
Err Posted September 10, 2007 Author Share Posted September 10, 2007 Are you talking about 2 different pages in 2 different browsers?-> [removed] isn't working right on your side? Do you have IE 7 and FF 2?I have IE6 and FF2 and I see it good even in Opera. Link to comment Share on other sites More sharing options...
Jesdisciple Posted September 10, 2007 Share Posted September 10, 2007 I was saying that they both worked in FF, but hadn't seen your edit. Link to comment Share on other sites More sharing options...
Err Posted September 10, 2007 Author Share Posted September 10, 2007 Well thanks for your input on this issue Jes. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.