Reputation: 392
window.onload=function(){
var day=new Date().getDay();
switch (day)
{
case 0:
window.document.location.href = 'su.html';
break;
case 1:
window.document.location.href = 'mo.html';
break;
case 2:
window.document.location.href = 'tu.html';
break;
case 3:
window.document.location.href = 'we.html';
break;
case 4:
window.document.location.href = 'th.html';
break;
case 5:
window.document.location.href = 'fr.html';
break;
case 6:
window.document.location.href = 'sa.html';
break;
}
};
it does not load the current html page. It loads the index.html file can somebody pls tell me how to make this could work ? thanks! i've got an array whith week days
Upvotes: 0
Views: 78
Reputation: 1211
You will need to change your script to something like this if you want to have the same script in every page:
window.onload=function(){
var day=new Date().getDay();
var path = window.location.pathname;
var page = path.split("/").pop();
if(day == 0 && page != 'su.html')
window.document.location.href = 'su.html';
else if(day == 1 && page != 'mo.html')
window.document.location.href = 'mo.html';
else if(day == 2 && page != 'tu.html')
window.document.location.href = 'tu.html';
else if(day == 3 && page != 'we.html')
window.document.location.href = 'we.html';
else if(day == 4 && page != 'th.html')
window.document.location.href = 'th.html';
else if(day == 5 && page != 'fr.html')
window.document.location.href = 'fr.html';
else if(day == 6 && page != 'sa.html')
window.document.location.href = 'sa.html';
};
Upvotes: 1
Reputation: 933
You can't put the javascript in every page, but only in a "loading" page that execute the code and navigate the user in the correct page.
Loading page (With your script) -> Go in the correct page
Upvotes: 1