0

While taking pring textbox also coming in print page and its look like bad UI. how can i remove that textbox and show only the text entered value.

Please find the image. How can I resolve this issue. I want to show only the text what I have entered in the textbox. Please help me how can I resolve this issue.

jsfiddle

<!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></title>
    <script type="text/javascript">
        function PrintDiv() {
            var contents = document.getElementById("dvContents").innerHTML;
            var frame1 = document.createElement('iframe');
            frame1.name = "frame1";
            frame1.style.position = "absolute";
            frame1.style.top = "-1000000px";
            document.body.appendChild(frame1);
            var frameDoc = frame1.contentWindow ? frame1.contentWindow : frame1.contentDocument.document ? frame1.contentDocument.document : frame1.contentDocument;
            frameDoc.document.open();
            frameDoc.document.write('<html><head><title>DIV Contents</title>');
            frameDoc.document.write('</head><body>');
            frameDoc.document.write(contents);
            frameDoc.document.write('</body></html>');
            frameDoc.document.close();
            setTimeout(function () {
                window.frames["frame1"].focus();
                window.frames["frame1"].print();
                document.body.removeChild(frame1);
            }, 500);
            return false;
        }
    </script>
</head>
<body>
    <form id="form1">
    <span style="font-size: 10pt; font-weight: bold; font-family: Arial">ASPSnippets.com
        Sample page</span>
    <hr />
    <div id="dvContents" style="border: 1px dotted black; padding: 5px; width: 300px">
        <span style="font-size: 10pt; font-weight: bold; font-family: Arial">Hello,
            <br />
            This is <span style="color: #18B5F0">Mudassar Khan</span>.<br />
            Hoping that you are enjoying my articles!</span>
            <input type="text" class="input printText" value="test">
    </div>
    <br />
    <input type="button" onclick="PrintDiv();" value="Print" />
    </form>
</body>
</html>
sathish kumar
  • 916
  • 1
  • 21
  • 58

2 Answers2

3

In this specific case, you can't add the CSS externally, but you have to do something like:

frameDoc.document.write('<style>@media print { input { border: none !important; } }</style>');
dgopsq
  • 144
  • 5
0

Duplicate of How do I hide an element when printing a web page?

Anyways,

    @media print{
        .noprint{
           display:none;
           content:"Hello! No printing allowed!";
        }
    }
<html>
<head>
</head>
<body>
<div class='noprint'>
Hello! Press CTRL P!
</div>
</body>
</html>

Put everything you don't want seen in the .noprint class, and it shouldn't 'display' when you print it.

EDIT:

It completely works for me. Did you really think I would post something without testing it first? If you're having trouble with it, then maybe you're just using a old browser. It's supported by Chrome 21, Explorer 9, Firefox 3.5, Safari 4.0 and Opera 9.

It's working as intended for me.

Lorddirt
  • 460
  • 3
  • 14