MozillaZine

Error, The document cannot change while Printing or in Print

Discuss how to use and promote Web standards with the Mozilla Gecko engine.
kravitz
 
Posts: 4
Joined: April 3rd, 2009, 10:20 am

Post Posted April 10th, 2009, 2:40 pm

When upgrading to the latest version of Firefox, the following error is reported after printing:

The document cannot change while Printing or in Print Preview

When the user selects a link on the page, the following JavaScript is called:

Code: Select all
    window.print();


When the print dialog is dismissed, the focus event occurs on the main window:

Code: Select all
    <body onFocus="refresh()">


and is handled by the refresh method. This changes the location from the web page for printing back to the main page:

Code: Select all
    function refresh() {
    window.location='new location';
    }


This worked fine until Firefox was upgraded. I am currently on 3.0.8 but it may have started failing in earlier versions.

Any suggestions?
Are there any events other than focus to listen for to avoid this message?

Thanks,

Ken

jscher2000

User avatar
 
Posts: 11069
Joined: December 19th, 2004, 12:26 am
Location: Silicon Valley, CA USA

Post Posted April 10th, 2009, 4:21 pm

Ideally, you would hook into the onafterprint Event, except that it only is not (yet) supported by Firefox. If you create a login for Bugzilla, you can vote for adding the event to Firefox. But please avoiding making "me too" comments in the bug. That will not help you make friends and influence people. ;)

Bug 307258 – Support onbeforeprint and onafterprint events

In the meantime, how about a little delay using setTimeout()?

kravitz
 
Posts: 4
Joined: April 3rd, 2009, 10:20 am

Post Posted April 13th, 2009, 5:58 am

Thank you for your reply. I have tried setTimeout. However, the page that is being rendered for printing can take an indeterminate time to complete drawing. It is unfortunate that the Mozilla platform has regressed on the printing capability. On Internet Explorer, the web application already uses onafterprint.

jscher2000

User avatar
 
Posts: 11069
Joined: December 19th, 2004, 12:26 am
Location: Silicon Valley, CA USA

Post Posted April 13th, 2009, 12:08 pm

kravitz wrote:I have tried setTimeout. However, the page that is being rendered for printing can take an indeterminate time to complete drawing.

I don't suppose you could use try/catch for this?

kravitz wrote:It is unfortunate that the Mozilla platform has regressed on the printing capability.

I wasn't aware that the behavior changed, and I have no idea why. Perhaps it was thought that most scripts should not be blocked by printing?

kravitz
 
Posts: 4
Joined: April 3rd, 2009, 10:20 am

Post Posted April 14th, 2009, 6:04 am

Try/catch still displays the error. Thanks.

Return to Web Development / Standards Evangelism


Who is online

Users browsing this forum: No registered users and 2 guests