Recently, I had the question "How to create a pop-up window that will be displayed only at a specified time." The user of the Rules forum helped me with this question. The code he gave me is:

<html> <head> <meta name="charset" content="utf-8"> <title>Окно</title> <style type="text/css"> #mywindow{ position: absolute; top: 25%; left: 25%; width: 50%; height: 50%; background-color: #FFF9AE; visibility: hidden; } #closewin{ position: absolute; top: 3px; right: 3px; width: auto; height: auto; background-color: #FFF9AE; text-decoration: underline; } #mywindow2{ position: absolute; top: 25%; left: 25%; width: 50%; height: 50%; background-color: #FFF9AE; visibility: hidden; } #closewin2{ position: absolute; top: 3px; right: 3px; width: auto; height: auto; background-color: #FFF9AE; text-decoration: underline; } </style> <script> function showWindow(){ var myWindow = document.getElementById("mywindow"); var myWindow2 = document.getElementById("mywindow2"); var nowDate = new Date(); if(nowDate.getDay() == 0 || nowDate.getDay() == 6){ myWindow.style.visibility = "visible"; } if(nowDate.getDay() == 1 || nowDate.getDay() == 2 || nowDate.getDay() == 3 || nowDate.getDay() == 4 || nowDate.getDay() == 5 || ( nowDate.getHours() <= 8 || nowDate.getHours() >= 21 )){ myWindow2.style.visibility = "visible"; } } function closeWin(){ var myWindow = document.getElementById("mywindow"); myWindow.style.visibility = "hidden"; } window.onload = showWindow; </script> </head> <body> <div id="mywindow"><div id="closewin" onclick="closeWin()">Закрыть</div>Выходной</div> <div id="mywindow2"><div id="closewin" onclick="closeWin()">Закрыть</div>Ночь</div> </body> </html> 

Now the question is different: how to make one window pop up at night, and another on the weekend.

  • 6
    code for you to write something? no, come on yourself buddy, and if that doesn't work you can ask, but no one will write the code for you - johniek_comp
  • 2
    And although ... Rightly said @johniek_comp, @ Pavlik290592 you will think it is in JavaScript Null or even Undefined :) But seriously, I write you the code and you get the money! So do not go try it yourself to organize it and if it does not work, ask for help (there you just need to copy and change) - Rules
  • one
    Help me please. - Pavlik290592
  • one
    > So it starts for me to just show the window of the day off, then the window is night. How many understood, did not understand why. And you will bring your code, I will correct it ... (it’s not a shame just capitalism) - Rules
  • one
    Now I will help - Rules

1 answer 1

I am busy here, I will edit the sample code later ...

 <html> <head> <meta name="charset" content="utf-8"> <title>Окно</title> <style type="text/css"> #mywindow1 { position: absolute; top: 25%; left: 25%; width: 50%; height: 50%; background-color: #FFF9AE; visibility: hidden; } #closewin1 { position: absolute; top: 3px; right: 3px; width: auto; height: auto; background-color: #FFF9AE; text-decoration: underline; } #mywindow2 { position: absolute; top: 25%; left: 25%; width: 50%; height: 50%; background-color: #FFF9AE; visibility: hidden; } #closewin2 { position: absolute; top: 3px; right: 3px; width: auto; height: auto; background-color: #FFF9AE; text-decoration: underline; } </style> <script> function showWindow() { var myWindow1 = document.getElementById("mywindow1"); var myWindow2 = document.getElementById("mywindow2"); var nowDate = new Date(); if (nowDate.getDay() == 0 || nowDate.getDay() == 6) { myWindow1.style.visibility = "visible"; } else if (nowDate.getHours() <= 8 || nowDate.getHours() >= 21 ) { myWindow2.style.visibility = "visible"; } } function closeWin(obj) { var myWindow = obj.parentNode; myWindow.style.visibility = "hidden"; } window.onload = showWindow; </script> </head> <body> <div id="mywindow1"> <div id="closewin1" onclick="closeWin(this)">Закрыть</div> Выходной </div> <div id="mywindow2"> <div id="closewin2" onclick="closeWin(this)">Закрыть</div> Ночь </div> </body> </html> 
  • Thank. Only I do not see the difference. - Pavlik290592
  • And the window does not close. Well, it's a small thing. - Pavlik290592
  • Everything (I was preparing to enter the Lyceum) corrected (I forgot to add that the parent of the cross should be closed and not the cross itself :)) And the difference is that you have so many || when it is possible to manage with one else and still in many ways but it's time for me to sleep accept the answer - Rules