Javascript.RU

Создать новую тему Ответ
 
Опции темы Искать в теме
  #1 (permalink)  
Старый 25.07.2015, 13:15
Аватар для jack3dm
Аспирант
Отправить личное сообщение для jack3dm Посмотреть профиль Найти все сообщения от jack3dm
 
Регистрация: 05.04.2015
Сообщений: 52

Открыть окно в определенное время
У меня есть скрипт.

<button onclick="openW()">CLICK</button>

		<script>

			function openW() {
    		window.open("http://www.milanuncios.com/renovar/?id=167095568");
    		window.open("http://www.milanuncios.com/renovar/?id=162660783");
    		window.open("http://www.milanuncios.com/renovar/?id=167064417");
    		window.open("http://www.milanuncios.com/renovar/?id=162521427");
    		window.open("http://www.milanuncios.com/renovar/?id=165202120");
    		window.open("http://www.milanuncios.com/renovar/?id=166183573");
    	}

		</script>


Как сделать что бы вторая ссылка открывалась в час дня?
Ответить с цитированием
  #2 (permalink)  
Старый 25.07.2015, 14:03
Аватар для jack3dm
Аспирант
Отправить личное сообщение для jack3dm Посмотреть профиль Найти все сообщения от jack3dm
 
Регистрация: 05.04.2015
Сообщений: 52

Всё. Решил.
//year, month 0-11, date, hour, min (can add ,sec,msec)
var now = new Date();

var hora01 = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 1, 0, 0, 0) - now;
var hora02 = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 2, 0, 0, 0) - now;
var hora03 = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 3, 0, 0, 0) - now;
var hora04 = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 4, 0, 0, 0) - now;
var hora05 = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 5, 0, 0, 0) - now;
var hora06 = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 6, 0, 0, 0) - now;
var hora07 = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 7, 0, 0, 0) - now;
var hora08 = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 8, 0, 0, 0) - now;
var hora09 = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 9, 0, 0, 0) - now;
var hora10 = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 10, 0, 0, 0) - now;
var hora11 = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 11, 0, 0, 0) - now;
var hora12 = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 12, 0, 0, 0) - now;
var hora13 = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 13, 0, 0, 0) - now;
var hora14 = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 14, 0, 0, 0) - now;
var hora15 = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 15, 0, 0, 0) - now;
var hora16 = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 16, 0, 0, 0) - now;
var hora17 = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 17, 0, 0, 0) - now;
var hora18 = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 18, 0, 0, 0) - now;
var hora19 = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 19, 0, 0, 0) - now;
var hora20 = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 20, 0, 0, 0) - now;
var hora21 = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 21, 0, 0, 0) - now;
var hora22 = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 22, 0, 0, 0) - now;
var hora23 = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 23, 0, 0, 0) - now;
var hora24 = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 24, 0, 0, 0) - now;
var horaTest01 = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 13, 1, 0, 0) - now;
var horaTest02 = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 13, 1, 40, 0) - now;
var horaTest03 = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 13, 1, 50, 0) - now;

setTimeout(function openW() {
    		window.open("http://www.milanuncios.com/renovar/?id=167095568");
    	}, horaTest01);

setTimeout(function openW() {
    		window.open("http://www.milanuncios.com/renovar/?id=162660783");
    	}, horaTest02);

setTimeout(function openW() {
    		window.open("http://www.milanuncios.com/renovar/?id=167064417");
    	}, horaTest03);



		</script>
Ответить с цитированием
  #3 (permalink)  
Старый 25.07.2015, 14:38
Профессор
Отправить личное сообщение для Rise Посмотреть профиль Найти все сообщения от Rise
 
Регистрация: 07.11.2013
Сообщений: 4,662

jack3dm, а если horaTestXX будет отрицательно?
Ответить с цитированием
  #4 (permalink)  
Старый 25.07.2015, 15:25
Аватар для jack3dm
Аспирант
Отправить личное сообщение для jack3dm Посмотреть профиль Найти все сообщения от jack3dm
 
Регистрация: 05.04.2015
Сообщений: 52

Немного подшаманил

<!DOCTYPE html>
<html>

	<head>
		<title>MILANUNCIOS</title>
		<style>
			.myButton{-moz-box-shadow:0 1px 0 0 #f0f7fa;-webkit-box-shadow:0 1px 0 0 #f0f7fa;box-shadow:0 1px 0 0 #f0f7fa;background:-webkit-gradient(linear,left top,left bottom,color-stop(.05,#33bdef),color-stop(1,#019ad2));background:-moz-linear-gradient(top,#33bdef 5%,#019ad2 100%);background:-webkit-linear-gradient(top,#33bdef 5%,#019ad2 100%);background:-o-linear-gradient(top,#33bdef 5%,#019ad2 100%);background:-ms-linear-gradient(top,#33bdef 5%,#019ad2 100%);background:linear-gradient(to bottom,#33bdef 5%,#019ad2 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#33bdef', endColorstr='#019ad2', GradientType=0);background-color:#33bdef;-moz-border-radius:6px;-webkit-border-radius:6px;border-radius:6px;border:1px solid #057fd0;display:inline-block;cursor:pointer;color:#fff;font-family:Times New Roman;font-size:28px;font-weight:700;padding:45% 25% 5%;margin-left:18%;margin-right:auto;text-decoration:none;text-shadow:0 -1px 0 #5b6178}.myButton:hover{background:-webkit-gradient(linear,left top,left bottom,color-stop(.05,#019ad2),color-stop(1,#33bdef));background:-moz-linear-gradient(top,#019ad2 5%,#33bdef 100%);background:-webkit-linear-gradient(top,#019ad2 5%,#33bdef 100%);background:-o-linear-gradient(top,#019ad2 5%,#33bdef 100%);background:-ms-linear-gradient(top,#019ad2 5%,#33bdef 100%);background:linear-gradient(to bottom,#019ad2 5%,#33bdef 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#019ad2', endColorstr='#33bdef', GradientType=0);background-color:#019ad2}.myButton:active{position:relative;top:1px;background:url([url]http://cs622123.vk.me/v622123065/1789f/rStcU0r40T0.jpg[/url]) 50% 50% no-repeat}
		</style>
	</head>

	<body>
		<button onclick="openW()" class="myButton">CLICK ME :3</button>
		<script>
/////////////////////////////////////////////////////////////////////////////////////		
/////////////////////////////////////////////////////////////////////////////////////		
/////////////////////////////////////////////////////////////////////////////////////		
/////////////////////////////////////////////////////////////////////////////////////		
/////////////////////////////////////////////////////////////////////////////////////		
/////////////////////////////////////////////////////////////////////////////////////		
/////////////////////////////////////При клике на кнопку открываются следующие ссылки
/////////////////////////////////////////////////////////////////////////////////////		
/////////////////////////////////////Порой выскакивает ошибка, нужно зайти в раздел
/////////////////////////////////////Modificar mis anuncios, автоматом открывается
/////////////////////////////////////одно окно при клике и когда срабатывает время
/////////////////////////////////////////////////////////////////////////////////////		
/////////////////////////////////////////////////////////////////////////////////////
			function openW() {
    		window.open("http://www.milanuncios.com/mis-anuncios/");
    		window.open("http://www.milanuncios.com/renovar/?id=167095568");
    		window.open("http://www.milanuncios.com/renovar/?id=162660783");
    		window.open("http://www.milanuncios.com/renovar/?id=167064417");
    		window.open("http://www.milanuncios.com/renovar/?id=162521427");
    		window.open("http://www.milanuncios.com/renovar/?id=165202120");
    		window.open("http://www.milanuncios.com/renovar/?id=166183573");
    	}
/////////////////////////////////////////////////////////////////////////////////////		
/////////////////////////////////////////////////////////////////////////////////////		
/////////////////////////////////////////////////////////////////////////////////////		
/////////////////////////////////////////////////////////////////////////////////////		
/////////////////////////////////////////////////////////////////////////////////////		
/////////////////////////////////////////////////////////////////////////////////////		
/////////////////////////////////////////////////////////////////////////////////////		
///////////////////////////////////////////////////////Переменные отвечающие за время
///////////////////////////////////////////////////////hora01 это час ночи (01:00)	
///////////////////////////////////////////////////////hora17 это 5 часов дня (17:00)	
/////////////////////////////////////////////////////////////////////////////////////		
/////////////////////////////////////////////////////////////////////////////////////
var now = new Date();

var hora01 = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 1, 0, 0, 0) - now;
var hora02 = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 2, 0, 0, 0) - now;
var hora03 = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 3, 0, 0, 0) - now;
var hora04 = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 4, 0, 0, 0) - now;
var hora05 = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 5, 0, 0, 0) - now;
var hora06 = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 6, 0, 0, 0) - now;
var hora07 = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 7, 0, 0, 0) - now;
var hora08 = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 8, 0, 0, 0) - now;
var hora09 = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 9, 0, 0, 0) - now;
var hora10 = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 10, 0, 0, 0) - now;
var hora11 = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 11, 0, 0, 0) - now;
var hora12 = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 12, 0, 0, 0) - now;
var hora13 = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 13, 0, 0, 0) - now;
var hora14 = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 14, 0, 0, 0) - now;
var hora15 = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 15, 0, 0, 0) - now;
var hora16 = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 16, 0, 0, 0) - now;
var hora17 = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 17, 0, 0, 0) - now;
var hora18 = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 18, 0, 0, 0) - now;
var hora19 = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 19, 0, 0, 0) - now;
var hora20 = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 20, 0, 0, 0) - now;
var hora21 = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 21, 0, 0, 0) - now;
var hora22 = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 22, 0, 0, 0) - now;
var hora23 = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 23, 0, 0, 0) - now;
var hora24 = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 24, 0, 0, 0) - now;

if (hora01  < 0) { hora01 += 86400000; };
if (hora02  < 0) { hora02 += 86400000; };
if (hora03  < 0) { hora03 += 86400000; };
if (hora04  < 0) { hora04 += 86400000; };
if (hora05  < 0) { hora05 += 86400000; };
if (hora06  < 0) { hora06 += 86400000; };
if (hora07  < 0) { hora07 += 86400000; };
if (hora08  < 0) { hora08 += 86400000; };
if (hora09  < 0) { hora09 += 86400000; };
if (hora10  < 0) { hora10 += 86400000; };
if (hora11  < 0) { hora11 += 86400000; };
if (hora12  < 0) { hora12 += 86400000; };
if (hora13  < 0) { hora13 += 86400000; };
if (hora14  < 0) { hora14 += 86400000; };
if (hora15  < 0) { hora15 += 86400000; };
if (hora16  < 0) { hora16 += 86400000; };
if (hora17  < 0) { hora17 += 86400000; };
if (hora18  < 0) { hora18 += 86400000; };
if (hora19  < 0) { hora19 += 86400000; };
if (hora20  < 0) { hora20 += 86400000; };
if (hora21  < 0) { hora21 += 86400000; };
if (hora22  < 0) { hora22 += 86400000; };
if (hora23  < 0) { hora23 += 86400000; };
if (hora24  < 0) { hora24 += 86400000; };
/////////////////////////////////////////////////////////////////////////////////////		
/////////////////////////////////////////////////////////////////////////////////////		
/////////////////////////////////////////////////////////////////////////////////////		
/////////////////////////////////////////////////////////////////////////////////////		
/////////////////////////////////////////////////////////////////////////////////////		
/////////////////////////////////////////////////////////////////////////////////////		
/////////////////////////////////////////////////////////////////////////////////////		
//////////////////////////////////////////////Ссылка открывается когда приходит время
/////////////////////////////////////////////////////////////////////////////////////		
/////////////////////////////////////////////////////////////////////////////////////
setTimeout(function openW() {
    		window.open("http://www.milanuncios.com/mis-anuncios/");
    		window.open("http://www.milanuncios.com/renovar/?id=167095568");
    	}, hora01);//01:00

setTimeout(function openW() {
    		window.open("http://www.milanuncios.com/mis-anuncios/");
    		window.open("http://www.milanuncios.com/renovar/?id=162660783");
    	}, hora02);//02:00

setTimeout(function openW() {
    		window.open("http://www.milanuncios.com/mis-anuncios/");
    		window.open("http://www.milanuncios.com/renovar/?id=167064417");
    	}, hora03);//03:00

		</script>
	</body>
</html>
Ответить с цитированием
  #5 (permalink)  
Старый 25.07.2015, 15:26
Аватар для jack3dm
Аспирант
Отправить личное сообщение для jack3dm Посмотреть профиль Найти все сообщения от jack3dm
 
Регистрация: 05.04.2015
Сообщений: 52

Сообщение от Rise Посмотреть сообщение
jack3dm, а если horaTestXX будет отрицательно?
А когда она может быть отрицательной? О_о
Я утром встаю и обновляю эту страничку у себя, она будет работать пока я её не выключу. Или я где то накосячил?
Ответить с цитированием
  #6 (permalink)  
Старый 25.07.2015, 16:04
Профессор
Отправить личное сообщение для Rise Посмотреть профиль Найти все сообщения от Rise
 
Регистрация: 07.11.2013
Сообщений: 4,662

Сообщение от jack3dm Посмотреть сообщение
А когда она может быть отрицательной? О_о
Я утром встаю и обновляю эту страничку у себя, она будет работать пока я её не выключу. Или я где то накосячил?
В 6 утра встал обновил, hora01 - hora06 в минус ушли
Ответить с цитированием
  #7 (permalink)  
Старый 25.07.2015, 16:44
Аватар для jack3dm
Аспирант
Отправить личное сообщение для jack3dm Посмотреть профиль Найти все сообщения от jack3dm
 
Регистрация: 05.04.2015
Сообщений: 52

Сообщение от Rise Посмотреть сообщение
В 6 утра встал обновил, hora01 - hora06 в минус ушли
Что то новое для меня. Не думал об этом.
В таком случае hora01-hora06 мусор? Или как? Как мне с ними бороться?
Я новичок в JS и программировании в общем.
Ответить с цитированием
Ответ



Опции темы Искать в теме
Искать в теме:

Расширенный поиск


Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Открыть новое окно (вкладку) с текстом из div-а с определенным ID Globus Элементы интерфейса 6 04.03.2014 19:56
Скрыть окно через определенное время fe1ix Общие вопросы Javascript 4 26.09.2013 10:00
Position fixed, но динамический по оси ОХ tvixa Элементы интерфейса 4 09.09.2013 15:39
Динамическое создание iframe в Firefox mrbean11 Firefox/Mozilla 8 02.11.2012 21:23
Подскажите как открыть модальное окно "fancybox" из скрипта js dgabets jQuery 1 18.02.2012 18:05