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>
// 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;
}
}