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

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

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

Докладніше

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

Javascript Redirection Not Working

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

more options

Hello,

I have a web page that prints a document, and then redirects back to the main page. This website has always worked in every browser, and now in Firefox 84.0.2 it no longer redirects.

What changed in Firefox, and how do I get it redirecting again?

Here is a snippet of the code in question:

<script type='text/javascript'>

    var interval = setInterval(function() {
         if(document.readyState === 'complete') {
              clearInterval(interval);
              window.print();
         }
    }, 100);
    
    window.onbeforeprint = function() {
         window.location = 'https://www.mozilla.org';
    }

</script>

Hello, I have a web page that prints a document, and then redirects back to the main page. This website has always worked in every browser, and now in Firefox 84.0.2 it no longer redirects. What changed in Firefox, and how do I get it redirecting again? Here is a snippet of the code in question: <script type='text/javascript'> var interval = setInterval(function() { if(document.readyState === 'complete') { clearInterval(interval); window.print(); } }, 100); window.onbeforeprint = function() { window.location = 'https://www.mozilla.org'; } </script>

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

more options

FWIW this is the type of issue to report at https://bugzilla.mozilla.org/ rather than this end user support forum.

That said, it seems weird that you would navigate away from the page to be printed in `onbeforeprint`. Why not `onafterprint`?

more options

Jonathan Watt said

FWIW this is the type of issue to report at https://bugzilla.mozilla.org/ rather than this end user support forum. That said, it seems weird that you would navigate away from the page to be printed in `onbeforeprint`. Why not `onafterprint`?

Hi Jonathan,

Thank you for the reply. I use onbeforeprint in Firefox, because onafterprint does not seem to work.

For the time being, and just in case anyone else is having the issue, I have found that using a seperate setTimeout with an interval of 5 seconds seems to work for my purpose.