Chrome — problem with printing


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
28 views
Welcome!

Problem: need to print some text using JS.

Create iframe to insert the text there, and bring up the print dialog: frames['frame-print'].print();

Everything seems to be working, click our button appears in the print window, click the Print button and you're done.

But in Chrome there is such a problem, if you close the dialog box and the cross or Cancel button, then pressing the print (js) get the message: Ignoring too frequent calls to print().

After a minute begins to work again.

Can this somehow be avoided or cured?
by | 28 views

2 Answers

0 like 0 dislike
Try this:
\r
Script:
\r
Copy Source | Copy HTML\rfunction PrintIt(){ \r var ua=navigator.userAgent;\r var ie=/MSIE/.test(ua);\r stext=";\r stext=document.getElementById("Printable").innerHTML;\r wnd=window.open("", "tinyWindow", 'statusbar=no,toolbar=no,scrollbars=yes,resizable=yes,width=630,height=900');\r wnd.document.write("
\rPrint page
\r
\r
\r
\r
\rthe beginning of the sheet
"
);
\r
wnd.document.write(stext);\r if (!ie){\r wnd.document.write("the end of the sheet
"
);
\r
wnd.print();\r }else{\r wnd.document.write("window.onload=self.print();<\\/script>");\r wnd.location.reload()\r }\r} \r

(Remove the line breaks from all items in the wnd.document.write)
\r
The scope and challenge:
\r
Copy Source | Copy HTML\rContent for print
\r
\r
by
0 like 0 dislike
src.chromium.org/viewvc/chrome/trunk/src/chrome/renderer/print_web_view_helper_win.cc?revision=27421&view=markup&pathrev=31561
\r
At this address you can see:
\r
\r
// TODO(maruel): Move this out of platform specific code. // Check if there is a script repeatedly trying to print and ignore it if too // frequent. We use exponential wait time so for a page that calls print() in // a loop the user will need to cancel the print dialog after 2 seconds, 4 // seconds, 8, ... up to the maximum of 2 minutes. // This gives the user time to navigate from the page. if (script_initiated && (user_cancelled_scripted_print_count_ > 0)) { base::TimeDelta diff = base::Time::Now() - last_cancelled_script_print_; int min_wait_seconds = std::min( kMinSecondsToIgnoreJavascriptInitiatedprint <<(user_cancelled_scripted_print_count_ - 1), kMaxSecondsToIgnoreJavascriptInitiatedprint); if (diff.InSeconds() < min_wait_seconds) { WebString message(WebString::fromUTF8( "Ignoring too frequent calls to print().")); frame->addMessageToConsole(WebConsoleMessage( WebConsoleMessage::LevelWarning, message)); return; } } 

\r
As I understand it — there is hard-Packed delay.
by

Related questions

0 like 0 dislike
3 answers
0 like 0 dislike
3 answers
0 like 0 dislike
3 answers
0 like 0 dislike
1 answer
0 like 0 dislike
2 answers
110,608 questions
257,186 answers
0 comments
27,905 users