Цей вебсайт матиме обмежену функціональність, доки ми проводимо його обслуговування для поліпшення роботи. Якщо прочитана стаття не розв'язала вашу проблему і ви хочете поставити питання, наша спільнота підтримки з радістю допоможе вам на @FirefoxSupport у Twitter та /r/firefox на Reddit.

Шукати в статтях підтримки

Остерігайтеся нападів зловмисників. Mozilla ніколи не просить вас зателефонувати, надіслати номер телефону у повідомленні або поділитися з кимось особистими даними. Будь ласка, повідомте про підозрілі дії за допомогою меню “Повідомити про зловживання”

Докладніше

Ця тема перенесена в архів. Якщо вам потрібна допомога, запитайте.

settimeout never pops

  • 2 відповіді
  • 1 має цю проблему
  • 1 перегляд
  • Остання відповідь від jamescobban

more options

I have a piece of code which has worked fine since I wrote it almost 20 years ago and which has only been fine tuned as the standards for JavaScript have been refined over those two decades. The functionality is to act when the user stops typing into a textbox for 0.9 seconds, which by trial and error I found was fast enough to act without premature invocation because the user was just typing slowly.

```javascript // in the initialization code element.addEventListener('keydown', onKeyDownName); ... function onKeyDownName(event) {

   if (timer)
       clearTimeout(timer);
   timer   = setTimeout(update, 900);
   alert("nominalIndex.js: onKeyDownName: timer=" + timer)

} // function onKeyDownName

function update() {

   alert("nominalIndex.js: update:");
   // perform the function

} ```

The alerts are only inserted, on my private test site only, to try and debug why this code is no longer working. Each time I type a character I see the alert "nominalIndex.js: onKeyDownName: timer=nnn" but no matter how long I wait I never see the alert "nominalIndex.js: update:". To get the function to work the user must take some other action which causes the function update to be called. There are no messages in the log to explain why the timer isn't popping. How can I debug this?

The code works on Chromium 87.0.4280.88 but doesn't work on FireFox 83.0 build id 20201112153044. I am running Ubuntu Linux 20.04

See this code in action at www.jamescobban.net/FamilyTree/nominalIndex.php?name=Culbert%2C%20Su&treename=&lang=en

I have a piece of code which has worked fine since I wrote it almost 20 years ago and which has only been fine tuned as the standards for JavaScript have been refined over those two decades. The functionality is to act when the user stops typing into a textbox for 0.9 seconds, which by trial and error I found was fast enough to act without premature invocation because the user was just typing slowly. ```javascript // in the initialization code element.addEventListener('keydown', onKeyDownName); ... function onKeyDownName(event) { if (timer) clearTimeout(timer); timer = setTimeout(update, 900); alert("nominalIndex.js: onKeyDownName: timer=" + timer) } // function onKeyDownName function update() { alert("nominalIndex.js: update:"); // perform the function } ``` The alerts are only inserted, on my private test site only, to try and debug why this code is no longer working. Each time I type a character I see the alert "nominalIndex.js: onKeyDownName: timer=nnn" but no matter how long I wait I never see the alert "nominalIndex.js: update:". To get the function to work the user must take some other action which causes the function update to be called. There are no messages in the log to explain why the timer isn't popping. How can I debug this? The code works on Chromium 87.0.4280.88 but doesn't work on FireFox 83.0 build id 20201112153044. I am running Ubuntu Linux 20.04 See this code in action at www.jamescobban.net/FamilyTree/nominalIndex.php?name=Culbert%2C%20Su&treename=&lang=en

Обране рішення

Noting that on a second computer with the same version of Firefox installed the script worked properly I rebooted my system and now the script works. in FF 83.0. I guess this was just the sort of minor corruption that even Linux is susceptible to.

Читати цю відповідь у контексті 👍 0

Усі відповіді (2)

more options

As far as I tested your code it works as expected in firefox 84 and 82 on linux (don't have 83 rn), also in chrome. Also the website work similarly in chrome an ff. You can step through the event functions or add some proxy for those event handlers to investigate. Maybe an extension doing something?

more options

Вибране рішення

Noting that on a second computer with the same version of Firefox installed the script worked properly I rebooted my system and now the script works. in FF 83.0. I guess this was just the sort of minor corruption that even Linux is susceptible to.