У меня есть контент в области div.Я хочу взять распечатку выбранного контента из div.В моем javsscript,
Например, если я выбираю 3 строки из содержимого div, после распечатки , я получаю содержимое из 3 строк как одну строку.не 3 строка.
Мой код
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://richfaces.org/rich" prefix="rich" %>
<%@ taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
<f:view>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript">
function printPartialContent(divContentId)
{
var selectedContent = "";
selectedContent= document.getSelection();
var textPopupWindow = window.open('','popup','toolbar=no,menubar=no,width=1,height=1 left=-5000');
textPopupWindow.document.open();
textPopupWindow.document.write(makeTextPrint(selectedContent));
textPopupWindow.document.close();
}
function makeTextPrint(textContent)
{
// We break the closing script tag in half to prevent
// the HTML parser from seeing it as a part of
// the *main* page.
return "<html>\n" +
"<head>\n" +
"<script>\n" +
"function step1() {\n" +
" setTimeout('step2()', 10);\n" +
"}\n" +
"function step2() {\n" +
" window.print();\n" +
" window.close();\n" +
"}\n" +
"</scr" + "ipt>\n" +
"</head>\n" +
"<body onLoad='step1()'>\n" +
textContent +
"</body>\n" +
"</html>\n";
}
</script>
</head>
<body>
<h:form id="parameterform">
<rich:panel id="divPanelPanel">
<f:facet name="header">
<h:outputText value="Div Content Demo"/>
</f:facet>
<a4j:outputPanel id="divOutputPanel">
<div id="contentDivId" style="text-align:left">
******* Details 1 *******<br>
28/02/2011 08.19.00<br>
5641620100333718 566<br>
Value: 2000<br>
Counter : 123<br>
******* Details 2 *******<br>
16/10/2000 9.10.00<br>
56345345333718<br>
Value: 3000<br>
Counter : 765<br>
</div>
<a4j:commandButton value="Partial Content"
onclick="printPartialContent('contentDivId')"/>
</a4j:outputPanel>
</rich:panel>
</h:form
</body> </html></f:view>
Помогите мне.Заранее спасибо