Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Web page printing

Posted on 2002-06-10
14
Medium Priority
?
179 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 400 total points
ID: 7068660
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
ID: 7070113
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
ID: 7070149
Good luck and thanx for the "A".

CJ
0
Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

 

Expert Comment

by:conman2k
ID: 7070919
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
ID: 7070932
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
ID: 7070933
or save the page locally and print :-)
0
 
LVL 19

Expert Comment

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

CJ
0
 

Expert Comment

by:conman2k
ID: 7070960
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
ID: 7070983
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
ID: 7070999
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
ID: 7072956
Well since NS doesn't support some of those styles.. I doubt it will work in NS.

CJ
0
 

Author Comment

by:tdenny
ID: 7073220
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
ID: 7073296
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
ID: 7073355
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

879 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