Estoy ajustando con el script de Twisty: uso de Jquery UI Datepicker para redirigir a la URL: cambie el valor de la URL según la fecha seleccionada
Estoy intentando que el usuario haga clic en una fecha que se redirigirá a una página según la fecha seleccionada.
Si el usuario hace clic el 18 de enero, debe redirigirse a datpicker.com/18-01-2022. Si se selecciona la fecha del 22 de marzo, debe ir a datpicker.com/22-03-2022.
Pero estoy recibiendo esta alerta: redireccionar a indefinido, sin importar cómo modifiqué el script. Por lo tanto, agradecería su ayuda. Gracias.
Selecciona una fecha:
<script> $(function() { function getDayOfYear(n) { var s = new Date(n.getFullYear(), 0, 0); var d = (n - s) + ((s.getTimezoneOffset() - n.getTimezoneOffset()) * 60 * 1000); var oneDay = 1000 * 60 * 60 * 24; var day = "00" + Math.floor(d / oneDay); return day.substr(-3); } var targetUrl; $("#datepicker") .datepicker({ dateFormat: 'dd-mm-yy', onSelect: function(dateText) { datePicked = $.datepicker.parseDate('dd-mm-yy', dateText); dayPicked = getDayOfYear(datePicked); targetUrl = "https://datpicker.com/" + dayPicked; $(this).change(); } }) .change(function() { alert("Redirect to " + targetUrl); //window.location.href = targetUrl; }); }); </script>window.open('https://www.abdo-host.com', '_blank');o
var link = document.createElement("a"); link.href = 'https://www.abdo-host.com'; link.target = '_blank'; var event = new MouseEvent('click', { 'view': window, 'bubbles': false, 'cancelable': true }); link.dispatchEvent(event);