--<< Возврат к содержанию >>-- Назад

ASP: СОВЕТЫ РАЗРАБОТЧИКУ
http://www.relib.com/

Как печатать через скрипт

В Netscape Navigator 4 и Internet Explorer 5 печать страницы возможна через метод print(). В Internet Explorer 4 надо включить объект web browser в страницу и вызвать команду печати (данная функция невозможна в Netscape или Internet Explorer версии 3).

<html>
<head>
<script language="javascript">
<!--
// a little variable because IE3 isn't nice about testing
// for objects in vbscript
DA = (document.all) ? 1 : 0
window.onerror=handle_error
function handle_error()
{
 msg="\nNothing was printed. \n\nIf you do want to print this page,"
 msg+="then\nclick on the printer icon in the toolbar above."
 alert(msg)
 // to cancel the script error warning
 return true;
}
//-->
</script>
<SCRIPT LANGUAGE="VBScript">
sub print
 olecmd = 6    ' Print Command
 oleparam = 1
 on error resume next
 WB.ExecWB olecmd, oleparam
 if err.number <> 0 then
    if DA then ' ie4 - user probably cancelled
  alert "Nothing was printed."
    else  ' ie3 - give other instructions
  handle_error
    end if
 end if
end sub
</SCRIPT>
</head>
<body>
<form>
 <Input type=button value="print page" onclick="window.print();">
</form>
<OBJECT ID="WB"
  WIDTH=0 HEIGHT=0
  CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2">
</OBJECT>
</BODY>
</HTML>
 

--<< Возврат к содержанию >>-- Назад