Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Your code can be refined more.</p> <p>But before that, you may want to use the "official" way of detecting the version of IE: (<a href="http://msdn.microsoft.com/en-us/library/ms537509%28v=vs.85%29.aspx" rel="nofollow">From Detecting Internet Explorer More Effectively</a>)</p> <pre><code>function getInternetExplorerVersion() // Returns the version of Internet Explorer or a -1 // (indicating the use of another browser). { var rv = -1; // Return value assumes failure. if (navigator.appName == 'Microsoft Internet Explorer') { var ua = navigator.userAgent; var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})"); if (re.exec(ua) != null) rv = parseFloat( RegExp.$1 ); } return rv; } </code></pre> <p>Now, lets work on the logic:</p> <ul> <li>If the browser is IE6 or lower it will use "horarios2.png" for the img src and no other. </li> <li>And if its any other browser that it will check the weekday(0-6) so that it will fill in the specific image for each day. <ul> <li>From Monday(1) to Wensday(3) the image is suposed to be "quarta.png". </li> <li>The other day's have their own image </li> </ul></li> </ul> <p>:</p> <pre><code>function horario () { var imageName = ""; if(getInternetExplorerVersion() &lt;= 6) { imageName = "img/horarios2.png"; return; } var date = new Date(); var weekday = (date.getDay()); switch(weekday) { case 0: imageName = "img/domingo.png"; break; case 1: case 2: case 3: imageName = "img/quarta.png"; break; case 4: imageName = "img/quinta.png"; break; case 5: imageName = "img/sexta.png"; break; case 6: imageName = "img/sabado.png"; break; default: imageName = "img/horarios2.png"; } document.getElementById('horarios').src = imageName; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload