Список вопросов
Как зайти в Даркнет?!
25th January, 01:11
5
0
Как в tkinter из поля ввода Entry получить значение в одну переменную и обновить строку кнопкой, затем получить ещё одно введённое значение и затем сложить их. Ниже пример кода
21st July, 19:00
893
0
Программа, которая создает фейковые сервера в поиске игровых серверов CS 1.6 Steam
21st March, 17:43
948
0
Очень долго работает Update запрос Oracle
27th January, 09:58
912
0
не могу запустить сервер на tomcat HTTP Status 404 – Not Found
21st January, 18:02
905
0
Где можно найти фрилансера для выполнения поступающих задач, на постоянной основе?
2nd December, 09:48
938
0
Разработка мобильной кроссплатформенной военной игры
16th July, 17:57
1724
0
период по дням
25th October, 10:44
3955
0
Пишу скрипты для BAS только на запросах
16th September, 02:42
3720
0
Некорректный скрипт для закрытия блока
14th April, 18:33
4613
0
прокидывать exception в блоках try-catch JAVA
11th March, 21:11
4381
0
Помогите пожалуйста решить задачи
24th November, 23:53
6085
0
Не понимаю почему не открывается детальное описание продукта
11th November, 11:51
4350
0
Нужно решить задачу по программированию на массивы
27th October, 18:01
4395
0
Метода Крамера С++
23rd October, 11:55
4309
0
помогите решить задачу на C++
22nd October, 17:31
4002
0
Помогите решить задачу на python с codeforces
22nd October, 11:11
4492
0
Python с нуля: полное руководство для начинающих
18th June, 13:58
2599
0
Chrome — проблема с выводом на печать
Просмотров: 275
 
Ответов: 2
Приветствую!
Задача: необходимо выводить на печать некий текст с помощью JS.
Создаем iframe вставляем туда текст, и выводим диалоговое окно печати: frames['frame-print'].print();
Все вроде бы работает, жмем нашу кнопку появляется окно печати, жмем кнопку Печать и все готово.
Но в Chrome наблюдается такая проблема, если если закрыть диалоговое окно крестом и или кнопкой Отмена, то при повторном нажатии на печать (js) получаем сообщение: Ignoring too frequent calls to print().
Где-то через минуту начитает опять работать.
Можно ли это как-то обойти или вылечить?
Попробуйте так:
Скрипт:
Copy Source | Copy HTML
- function PrintIt(){
- var ua=navigator.userAgent;
- var ie=/MSIE/.test(ua);
- stext='';
- stext=document.getElementById("Printable").innerHTML;
- wnd=window.open("", "tinyWindow", 'statusbar=no,toolbar=no,scrollbars=yes,resizable=yes,width=630,height=900');
- wnd.document.write("<html>
<title>Печать страницы</title>
<head>
<link href=\"/style/print.css\"rel=\"stylesheet\"type=\"text/css\" media=\"all\"/></style>
</head>
<body onclick=\"window.close()\">
<div id=\"watermark-top\">начало листа</div>");
- wnd.document.write(stext);
- if (!ie){
- wnd.document.write("<div id=\"watermark-bottom\">конец листа</div><body></html>");
- wnd.print();
- }else{
- wnd.document.write("<script>window.onload=self.print();<\/script></body></html>");
- wnd.location.reload()
- }
- }
(Уберите переносы строки у всех элементов в wnd.document.write)
Область и вызов:
Copy Source | Copy HTML
- <div id="Printable">Контент для печати</div>
- <button onclick="PrintIt();">Печать</button>
Copy Source | Copy HTML
- function PrintIt(){
- var ua=navigator.userAgent;
- var ie=/MSIE/.test(ua);
- stext='';
- stext=document.getElementById("Printable").innerHTML;
- wnd=window.open("", "tinyWindow", 'statusbar=no,toolbar=no,scrollbars=yes,resizable=yes,width=630,height=900');
- wnd.document.write("<html>
<title>Печать страницы</title>
<head>
<link href=\"/style/print.css\"rel=\"stylesheet\"type=\"text/css\" media=\"all\"/></style>
</head>
<body onclick=\"window.close()\">
<div id=\"watermark-top\">начало листа</div>");
- wnd.document.write(stext);
- if (!ie){
- wnd.document.write("<div id=\"watermark-bottom\">конец листа</div><body></html>");
- wnd.print();
- }else{
- wnd.document.write("<script>window.onload=self.print();<\/script></body></html>");
- wnd.location.reload()
- }
- }
Copy Source | Copy HTML
- <div id="Printable">Контент для печати</div>
- <button onclick="PrintIt();">Печать</button>
src.chromium.org/viewvc/chrome/trunk/src/chrome/renderer/print_web_view_helper_win.cc?revision=27421&view=markup&pathrev=31561
По этому адресу видим:
// TODO(maruel): Move this out of platform specific code.
// Check if there is 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;
}
}
Как я понял — там жестко забита задержка…
// TODO(maruel): Move this out of platform specific code.
// Check if there is 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;
}
}
Чтобы ответить на вопрос вам нужно войти в систему или зарегистрироваться