打印预览简单实用代码实例
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>PrintReview</title>
<style type="text/css" media="screen">
<!--
.style1 {color: #FF0000;}
-->
</style>
<style type="text/css" media="print">
<!--
.style1 {color: #0000FF;}
.PrintNone { display:none;}
-->
</style>
<script language="javascript" >
function Print(OleCmdID, Prompt) {
/*
* OleCmdID values:
* 1 - Open Window
* 4 - Save As
* 6 - Print
* 7 - Print Preview
* 8 - Print Set
* 45- Close Window
*/
var WebBrowser = "<OBJECT ID='WebBrowser1' style='display:none' WIDTH=0 HEIGHT=0 CLASSID='CLSID:8856F961-340A-11D0-A96B-00C04FD705A2'></OBJECT>";
document.body.insertAdjacentHTML("beforeEnd", WebBrowser);
WebBrowser1.ExecWB(OleCmdID, Prompt);
WebBrowser1.outerHTML = "";
}
</script>
</head>
<body>
<input name="txtTest" type="text" class="style1 PrintNone" value="first"/>
<input name="txtTest" type="text" class="style1" value="second" />
<input type="button" name="btnPrint" value="Print Review" class="PrintNone" onClick="Print(7,1);" />
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>PrintReview</title>
<style type="text/css" media="screen">
<!--
.style1 {color: #FF0000;}
-->
</style>
<style type="text/css" media="print">
<!--
.style1 {color: #0000FF;}
.PrintNone { display:none;}
-->
</style>
<script language="javascript" >
function Print(OleCmdID, Prompt) {
/*
* OleCmdID values:
* 1 - Open Window
* 4 - Save As
* 6 - Print
* 7 - Print Preview
* 8 - Print Set
* 45- Close Window
*/
var WebBrowser = "<OBJECT ID='WebBrowser1' style='display:none' WIDTH=0 HEIGHT=0 CLASSID='CLSID:8856F961-340A-11D0-A96B-00C04FD705A2'></OBJECT>";
document.body.insertAdjacentHTML("beforeEnd", WebBrowser);
WebBrowser1.ExecWB(OleCmdID, Prompt);
WebBrowser1.outerHTML = "";
}
</script>
</head>
<body>
<input name="txtTest" type="text" class="style1 PrintNone" value="first"/>
<input name="txtTest" type="text" class="style1" value="second" />
<input type="button" name="btnPrint" value="Print Review" class="PrintNone" onClick="Print(7,1);" />
</body>
</html>