function displaymessage() { w...">

Write JavaScript on a html page javascript page

Here is my code:

    <html>
<head>
<script type="text/javascript">
function displaymessage()
{
win=window.open();
win.document.write("<html>");
win.document.write("<head>");
win.document.write("<style type=\"text/css\">");
win.document.write(".vis{visibility:hidden;}");
win.document.write("</style>");
win.document.write("</head>");
win.document.write("<body>");
win.document.write("<table align=\"center\">");
win.document.write("<tr><td>result:</td><td>100,--€</td></tr>");
win.document.write("<tr><td colspan=\"2\" id=\"idcko\"><input type=\"button\" value=\"click\" onclick=\"window.print();vlozenie()\"/></td></tr>");
win.document.write("</table>");
win.document.write("</body>");
win.document.write("</html>");
}
</script>
</head>
<body>
<form>
<input type="button" value="Click me!" onclick="displaymessage();" />
</form>
<script type="text/javascript">
function vlozenie()
{
var y = win.document.getElementById("idcko");
y.innerHTML="<input type=\"button\" value=\"click2\" class=\"vis\"/>";
}
</script>
</body>
</html>

Now I want to print the displayed page, but I want to hide the print button. So is it possible to write some JavaScript functions in the onclick event, or can I access the JavaScript function located on the main page? I found some examples for adding class attributes for HTML elements:

$("#idcko").addClass("vis");

but it should be written in JavaScript tags, which I cannot write as follows:

win.document.write("<script type=\"text/javascript\">some functions()</script>");

because the page displayed is incorrect.

+3
source share
2 answers

you can add css to your style @media printand then hide the element containing the printer icon withdisplay:none

@media print {
    selectorForPrinterIcon { display:none }
  }

, , , . , javascript.

+1

jquery $( "# PrintButtonId" ). hide()

, .

0

Source: https://habr.com/ru/post/1788955/


All Articles