<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<style type="text/css">
.pager
{
page-break-after:always;
color:Red;
}
.pager2
{
color:Red;
}
</style>
<object ID="WebBrowser" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></object>
<script type="text/javascript">
var xmlHttp;
var hkey_root, hkey_path, hkey_key;
hkey_root = "HKEY_CURRENT_USER";
hkey_path = "//Software//Microsoft//Internet Explorer//PageSetup//";
//设置网页打印的页眉页脚为空
function pagesetup_null() {
try {
var RegWsh = new ActiveXObject("WScript.Shell");
hkey_key = "header";
RegWsh.RegWrite(hkey_root + hkey_path + hkey_key, "");
hkey_key = "footer";
RegWsh.RegWrite(hkey_root + hkey_path + hkey_key, "");
} catch (e) { }
}
//设置网页打印的页眉页脚为默认值
function pagesetup_default(){
try {
var RegWsh = new ActiveXObject("WScript.Shell");
hkey_key = "header";
RegWsh.RegWrite(hkey_root + hkey_path + hkey_key, "&w&b页码,&p/&P");
hkey_key = "footer";
RegWsh.RegWrite(hkey_root + hkey_path + hkey_key, "&u&b&d");
} catch (e) { }
}
function createXMLHttpRequest() {
if (window.ActiveXObject) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} else if (window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
}
}
function startRequest() {
createXMLHttpRequest();
try {
xmlHttp.onreadystatechange = handleStateChange;
var dd = new Date().toTimeString();
xmlHttp.open("get", "data2.aspx?d=" + dd.toString(), true);
xmlHttp.send();
} catch (exception) {
alert("您要访问的资源不存在!");
}
}
function handleStateChange() {
if (xmlHttp.readyState == 4) {
if (xmlHttp.status == 200 || xmlHttp.status == 0) {
var str = xmlHttp.responseText;
var content = document.getElementById("content");
content.innerHTML= str;
}
}
}
function jj() {//直接在Table种添加"签名:"行
var content = document.getElementById("content");
var table = content.childNodes[0].childNodes[1].firstChild;
var totalHeight = 0;
table.style.borderWidth =0;
table.style.width =650;
for (var i = 0; i < table.rows.length; i++) {
totalHeight += table.rows[i].clientHeight+2;
if (totalHeight >900) {
var row = table.insertRow(i);
row.height = "20";
var xx = row.insertCell(0);
xx.colSpan = "7";
xx.style.borderWidth=0;
xx.innerHTML = "<div class='pager'>签名</div>";
totalHeight = 0;
}
}
var row = table.insertRow(table.rows.length);
row.height = "20";
var xx = row.insertCell(0);
xx.colSpan = "7";
xx.innerHTML = "<div class='pager2'>签名</div>";
xx.style.borderWidth = 0;
window.document.body.innerHTML = content.innerHTML;
WebBrowser.ExecWB(7, 1);
// window.print();
}
function insertAfter(newElement, targetElement) {
var parent = targetElement.parentNode;
if (parent.lastChild == targetElement) {
// 如果最后的节点是目标元素,则直接添加。
parent.appendChild(newElement);
} else {
parent.insertBefore(newElement, targetElement.nextSibling);
}
}
function print11() {
var divPrint = document.getElementById("Div1");
var div = document.createElement("div");
div.setAttribute("class", "pager");
div.innerHTML= "<font size='4'>签名</font>";
var content = document.getElementById("content");
var table = content.childNodes[0].childNodes[1].firstChild;
var totalHeight = 0;
alert(table.rows[0].clientHeight)
var copyTable = document.createElement("table");
var copyBody = document.createElement("tbody");
copyTable.setAttribute("border", "1");
copyTable.setAttribute("borderColor", "black");
// copyTable.setAttribute("width", "660");
copyTable.setAttribute("cellspacing", "0");
for (var i = 0; i < table.rows.length; i++) {
totalHeight = totalHeight+table.rows[i].clientHeight+2;
if (totalHeight <=820) {
var copyRow = table.rows[i].cloneNode(true);
copyBody.appendChild(copyRow);
}
else if (totalHeight >820) {
totalHeight = 0;
copyTable.appendChild(copyBody);
divPrint.appendChild(copyTable);
div=div.cloneNode(true);
divPrint.appendChild(div);
copyTable = document.createElement("table");
copyBody = document.createElement("tbody");
copyTable.setAttribute("border", "1");
copyTable.setAttribute("borderColor", "black");
//copyTable.setAttribute("width", "660");
copyTable.setAttribute("cellspacing", "0");
i--;
}
}
copyTable.appendChild(copyBody);
divPrint.appendChild(copyTable);
div = div.cloneNode(true);
div.setAttribute("class", "pager2");
divPrint.appendChild(div);
alert(table.rows[0].innerText)
window.document.body.innerHTML = divPrint.innerHTML;
// window.print();
WebBrowser.ExecWB(7, 1);
}
</script>
</head> <body>
<div>
<input type="button" value="return ajax responseXML's value" onclick="startRequest();" /> <input type="button" value="操作table" onclick="jj();" />
<input type="button" value="set" onclick="startRequest();" />
</div>
<div id="content" width="650"></div>
<div id="Div1"></div>
</body>
<script type="text/javascript">
function pvie() { WebBrowser.ExecWB(7, 1); }
</script>
</html>