3

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 rendered page, but I want to hide the print button. So is it possible to write some JavaScript functions in an "onclick" event, or may I access the JavaScript function which is located on the mother page? I found some examples to add "class" attributes for HTML elements:

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

but it has to be written in JavaScript tags, which I can`t write like this:

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

because the rendered page is now incorrect.

2 Answers 2

1

you can add in your css style @media print and then hide the element that contains the printer icon using display:none

@media print {
    selectorForPrinterIcon { display:none }
  }

Of course you can follow the same way to hide any other element that you want to be hidden in the printed version. So, there is no need for javascript.

Sign up to request clarification or add additional context in comments.

Comments

0

you need to just call jquery $("#PrintButtonId").hide()

hope this help.

3 Comments

He’s put his entire HTML page there in the question. Do you see jQuery linked to anywhere?
but he's use a jquery to add class. that's why? you seen this. if you want to hide button using javascript then add this line in javascript function: document.getelementbyid("printbuttonid").style.visibility='hidden';
The question though remains where would he put that javascript? Whether he is using Jquery or not is not really the point so much as where the script goes and how you write it there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.