Solved

Web page printing

Posted on 2002-06-10
14
134 Views
Last Modified: 2013-12-24
Is there any way to keep a user from being able to print a web page?  I know this is a long shot but just curious.
0
Comment
Question by:tdenny
  • 7
  • 4
  • 3
14 Comments
 
LVL 19

Accepted Solution

by:
cheekycj earned 100 total points
Comment Utility
AFAIK, this is not possible at all.

What you can do is make it harder for the user to print by using a dark background and light text (like black background with white text).. so if the user doesn't have print backgrounds enabled (most don't) then it will print as a blank page (white text on white paper)

CJ
0
 

Author Comment

by:tdenny
Comment Utility
CJ,

Thanks as usual for your response.  I didn't think there was any way possible but thought I'd ask for the heck of it.  Your work around is very clever though.  Take care
0
 
LVL 19

Expert Comment

by:cheekycj
Comment Utility
Good luck and thanx for the "A".

CJ
0
 

Expert Comment

by:conman2k
Comment Utility
You can prevent printing, do this:
<!-- STEP ONE: Copy the event handler into the BODY tag  -->


  <BODY onBeforePrint="document.body.style.display = 'none';"
        onAfterPrint="document.body.style.display = '';" ondragstart="return false" onselectstart="return false">


<!-- Script Size:  0.81 KB -->

The user will get a blank page as print output.

You can prevent 'right clicking' and 'copying' by using this javascript on the page:
<script language="JavaScript1.2">
<!--


top.window.moveTo(0,0);

//-->
</script>

<html>

<head>

<SCRIPT LANGUAGE="JavaScript">

<!--
var sorry="Sorry, copying or printing from this page is not allowed. This document is for internal use only."

function click(e)
{
    if (document.all)
    {
        if (event.button == 2)
        {
           alert(sorry);
           return false;
        }
    }
    if (document.layers)
    {
        if (e.which == 3)
        {
            alert(sorry);
            return false;
        }
    }
}

if (document.layers)
{
    document.captureEvents(Event.MOUSEDOWN);
}

document.onmousedown=click;
//-->

</SCRIPT>

Use both together and you have a pretty secure page. Even if a user is smart enough to do a control 'p', they still get a blank page.
0
 
LVL 19

Expert Comment

by:cheekycj
Comment Utility
those styles on work IE 5+, I believe.

also... a smart user will do cntrl-a and then paste and then print ;-)

CJ
0
 
LVL 19

Expert Comment

by:cheekycj
Comment Utility
or save the page locally and print :-)
0
 
LVL 19

Expert Comment

by:cheekycj
Comment Utility
sorry for all the posts.. but the best way to prevent someone from printing is don't put it on the web.

CJ
0
Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

 

Expert Comment

by:conman2k
Comment Utility
Incorrect. Try the code. I do this internally on our intranet for items we do not want to leave the building. Control A and Control C are prevented by the combo above. (I just verified it.) Control P works, but of course only a blank page is printed.

I prevent the saving of the page locally by having the text in question pop up in a window with no menu bars.

The only thing possible is a print screen copy, which gives them a graphic. If they are that desperate, they will just hand re-write it anyway.
0
 
LVL 19

Expert Comment

by:cheekycj
Comment Utility
onselect.. disables the selection of text.. I guess...
but how do you prevent cntrl-s.

and this doesn't work on NS does it... NS doesn't support those styles, as far as I know.

on the internet you can't control the user's browser type.

CJ
0
 

Expert Comment

by:conman2k
Comment Utility
Yea, in our controlled IE environment it works pretty well. On the Internet it would help, but not 100%.  I have not tried Netscape on the code since to save money we develop internally for just one browser. If someone tries it on Netscape, please let me know.

I just tried a control s and it does not work either. (this code rocks.)  I would imagine that there is similar code out there for Netscape.
0
 
LVL 19

Expert Comment

by:cheekycj
Comment Utility
Well since NS doesn't support some of those styles.. I doubt it will work in NS.

CJ
0
 

Author Comment

by:tdenny
Comment Utility
Conman, CJ,

Thanks again.  I will try it.  Unfortunately we are not limited to one browser.  In fact we used to be a NS only shop (this really stinks) - but we now are very slowly moving towards IE as the more commonly used browser.  I wish we could only code for one in our intranet.
0
 

Author Comment

by:tdenny
Comment Utility
Conman,

I tried your code and it works nicely.  I didn't try Netscape yet.  I am still able to use the Control C to cut and paste though.

I agree that not putting it on the web would be the best solution but we are giving our users a little test (nothing serious) and we were just trying to make sure that they didn't print all the correct answers and hand them off to the guy sitting next to them.  I'm assuming that they are smart enough to figure that out.  Again it's nothing serious.
0
 

Author Comment

by:tdenny
Comment Utility
Conman,

I tried your code and it works nicely.  I didn't try Netscape yet.  I am still able to use the Control C to cut and paste though.

I agree that not putting it on the web would be the best solution but we are giving our users a little test (nothing serious) and we were just trying to make sure that they didn't print all the correct answers and hand them off to the guy sitting next to them.  I'm assuming that they are smart enough to figure that out.  Again it's nothing serious.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now