-1

this is my first question on stackoverflow. I need some help because i need to pick a diferent html file for each day, i need to display a schedule for each day.

I got this javascript code on the web:

dayName = ["Domingo", "Lunes", "Martes", "Miercoles", "Jueves", "Viernes", "Sabado"];

dayNumber = new Date().getDay();

document.writeln('<link rel="stylesheet" type="text/css" href="' + dayName[dayNumber] + '.css">');

The code of above picks a different .css file for each day but i don't need that, i need to pick a html file.

Please help me and excuse me if my language isn't correct.

Thanks.

MrARC
  • 76
  • 2
  • Do you need a link to a different document each day, or display a different page each day? – TurboHz May 02 '14 at 20:12
  • Maybe this thread will help? http://stackoverflow.com/questions/503093/how-can-i-make-a-redirect-page-in-jquery-javascript – davidpm4 May 02 '14 at 20:13
  • `document.writeln` is discouraged (same for `document.write`) - do not use that. Instead, create the elements using `document.createElement` and/or `someElement.innerHTML` and/or `document.body.appendChild`. – PhistucK May 02 '14 at 20:13
  • This would be better handled on the server side. Do you have access to any server side processing like JSP, PHP, etc? – Steve May 02 '14 at 20:15
  • I don't have a server to do this, anyway thanks a lot for all your responses, my question got solved :) – MrARC May 02 '14 at 20:25

4 Answers4

0

The best way to do this would be with PHP and print out whatever HTML you want to send on the server, but if you don't know PHP or aren't able to use it for this, you could print all of the html in separate divs such as

<div class="Domingo"></div>
<div class="Lunes"></div>
etc.

and then pull in a stylesheet or use JavaScript that hides all the divs except the one you want to show.

CSS

.Domingo, .Lunes, .Martes, etc.{
    display: none;
}

JavaScript

dayName = ["Domingo", "Lunes", "Martes", "Miercoles", "Jueves", "Viernes", "Sabado"];
dayNumber = new Date().getDay();
$("." + dayName[dayNumber]).show();

This isn't the best thing to do because you will be sending all the days each time which will make the page load slower, but if isn't a super complicated project then this shouldn't be a problem.

Billy Jacobson
  • 1,608
  • 2
  • 13
  • 21
0

Welcome to Stack Overflow, user! If you wish to redirect to a different page, you can use the function location.replace() if you don't want to change the browser history, or use location.reload(); or location.href for if you do. So in your example, assuming it already works as-is:

dayName = ["Domingo", "Lunes", "Martes", "Miercoles", "Jueves", "Viernes", "Sabado"];

dayNumber = new Date().getDay();

// goes to new page without changing browser history.
location.replace("" + dayname[dayNumber] + ".htm");
// goes to new page and changes browser history.
location.reload("" + dayname[dayNumber] + ".htm");
// this also goes to the new page and changes browser history.
location.href="" + dayname[dayNumber] + ".htm";
tomysshadow
  • 870
  • 1
  • 8
  • 23
0

Why don't you redirect to the page you want? Using the same .css base you showed, it would be like this:

dayName = ["Domingo", "Lunes", "Martes", "Miercoles", "Jueves", "Viernes", "Sabado"];
dayNumber = new Date().getDay();

location.href = dayName[dayNumber] + ".html";
LcSalazar
  • 16,524
  • 3
  • 37
  • 69
0

Try using jQuery for this.

Example:

$(document).load(dayName[dayNumber]) + ".html");