Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

126
Views
Ejecute *.js si el mes es diciembre

Esta bien me rindo.

Estoy tratando de hacer este script

 <script> $(document).ready(function(){ var d = new Date(); n = d.getMonth(); if (n == 11) { src="extrafiles/effect/snow.js"; } }); </script>

llame a "snow.js" cada vez que el mes sea diciembre.

Aunque no funcionará. ¿Ideas?

EDITAR:

¿Quizás este es un mejor enfoque?

if ( d.getMonth().match(11) ) { //llamar a snow.js; }

EDIT2:

Esto funciona para determinar la temporada, modificable hasta el mes.

 <script> var currentTime = new Date(); var month = currentTime.getMonth() + 1; var total = month; if (total == 12 || total == 1 || total == 2) { //beginning of script START JS FILE VIA ??? //end of script } </script>
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Intenta hacerlo así:

 if (n === 11) { let myScript = document.createElement("script"); myScript.setAttribute("src", "https://www.example.com/snow.js"); document.body.appendChild(myScript); makeSnow(); }

o en modo ES6:

 <!doctype html> <script> async function load() { let say = await import('./snow.js'); say.makeSnow(); } </script> <button onclick="load()">Click me</button>
about 4 years ago · Juan Pablo Isaza Report

0

Puede hacer uso de la import para importar el archivo según su condición. También puede importar el archivo de todos modos y simplemente llamar a su función desde ese archivo dentro de su condicional.

 <DOCTYPE html> <head> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script> $(async () => { // same as $(document).ready(async function(){ const month = new Date().getMonth() if (month === 11) { const effect = await import('./snow.js') effect.run() } }) </script> </head> <body> </body>

Este es un ejemplo de solo importar el archivo al principio.

 <DOCTYPE html> <head> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script> const effect = await import('./snow.js') $(async () => { const month = new Date().getMonth() if (month === 11) { effect.run() } }) </script> </head> <body> </body>

Tenga en cuenta que esto generará un error en Stack Overflow porque ese archivo no existe, pero verifiqué que funciona localmente.

Como mostró el archivo, puedo ver que en realidad no exporta nada, por lo que la import no funcionará para usted aquí. En su lugar, tendrá que agregar retroactivamente el script al DOM

 <DOCTYPE html> <head> </head> <body> <script> document.addEventListener('DOMContentLoaded', () => { const s = document.createElement('script') s.type = 'text/javascript' s.src = 'https://ry3yr.github.io/OSTR/myhomepage/snow.js' document.body.appendChild(s) }) </script> </body>

about 4 years ago · Juan Pablo Isaza Report

0

Puede usar document.write para agregar el script

 if (new Date().getMonth()===11) document.write('<script src="https://ry3yr.github.io/OSTR/myhomepage/snow.js"><\/script>');

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!