ajosephson
asked on
Disable right click on images to stop saving.
I have seen this done on some sites..
How is it done?
I appreciate your help..
AJ
How is it done?
I appreciate your help..
AJ
it is an annoyance....if someone really wants your images, they can get them. they are allowed to download them to their browser, so the images are their's if they want them. i think i read about some server software you could install that protects images, but it went for a hefty sum
ASKER
I understand this... I am simply trying to inhibit the process. I appreciate computer savvy users will still find a way to capture the image...
AJ
AJ
ok then try this script:
"Disable Images Click"
http://javascript.internet.com/page-details/disable-images-click.html
"Disable Images Click"
http://javascript.internet.com/page-details/disable-images-click.html
ASKER
Thanks for the info.. It works OK, but when I try to use it with this code writen by ASPGuru (to hide the image URL) -
=====> pic.asp:
<%
Set objFileSystem = Server.CreateObject("Scrip ting.FileS ystemObjec t")
Set objFile = objFileSystem.GetFile(Serv er.mapPath ("secretDi r/img.jpg" ))
Set objStream = objFile.OpenAsTextStream(1 , TristateTrue)
Response.ContentType = "image/jpeg"
Response.AddHeader "content-length", objFile.Size
Do While Not objStream.AtEndOfStream
char = chrB(asc(objStream.Read(1) )) 'converting unicode to single Byte
Response.BinaryWrite(char)
Loop
%>
=====> test.html:
<HTML>
<BODY>
<img src="pic.asp">
</BODY></HTML>
Error - 'The HTTP headers are already written to the client browser' is returned.
Can the java script be simplified to disable right-click all together?
=====> pic.asp:
<%
Set objFileSystem = Server.CreateObject("Scrip
Set objFile = objFileSystem.GetFile(Serv
Set objStream = objFile.OpenAsTextStream(1
Response.ContentType = "image/jpeg"
Response.AddHeader "content-length", objFile.Size
Do While Not objStream.AtEndOfStream
char = chrB(asc(objStream.Read(1)
Response.BinaryWrite(char)
Loop
%>
=====> test.html:
<HTML>
<BODY>
<img src="pic.asp">
</BODY></HTML>
Error - 'The HTTP headers are already written to the client browser' is returned.
Can the java script be simplified to disable right-click all together?
this script shows how to achieve this for both the full page and just images...hopefully the former will work with your current implementation:
http://www.web-wise-wizard.com/javascript-tutorials/disable-right-click.html
http://www.web-wise-wizard.com/javascript-tutorials/disable-right-click.html
ajosephson,
the code ASPGuru gave you will work, but you have to make the line below the very first line of your script:
<% Response.Buffer = True %>
This will force IIS not to write the headers as they are defined, but buffer the page and only write headers after the entire script has run.
Note that that code only hides the URL, but it doesn't prevent users from saving the image if they want to. The best combination - almost fail safe - is ASPGuru's code along with some client-side scripting (like AzraSound has pointed you to).
Alex
the code ASPGuru gave you will work, but you have to make the line below the very first line of your script:
<% Response.Buffer = True %>
This will force IIS not to write the headers as they are defined, but buffer the page and only write headers after the entire script has run.
Note that that code only hides the URL, but it doesn't prevent users from saving the image if they want to. The best combination - almost fail safe - is ASPGuru's code along with some client-side scripting (like AzraSound has pointed you to).
Alex
ASKER
Thanks for the advice.. If I include <% Response.Buffer = True %> gibberish is returned.. I guess as the image is being sent (byte by byte?)
Here is how I've pieced it together -
<% Response.Buffer = True %>
<script language="JavaScript">
window.onload = trap_page_mouse_key_events ;
</script>
<script language="JavaScript">
function disable_right_click(e)
{
var browser = navigator.appName.substrin g ( 0, 9 );
var event_number = 0;
if (browser=="Microsoft")
event_number = event.button;
else if (browser=="Netscape")
event_number = e.which;
if ( event_number==2 || event_number==3 )
{
alert ("Right Mouse Button Is Disabled");
return (false);
}
return (true);
}
function check_mousekey ()
{
var mouse_key = 93;
var keycode = event.keyCode;
if ( keycode == mouse_key )
alert ( "Mouse Key Is Disabled" );
}
function trap_page_mouse_key_events ()
{
var browser = navigator.appName.substrin g ( 0, 9 );
document.onmousedown = disable_right_click;
if ( browser == "Microsoft" )
document.onkeydown = check_mousekey;
else if ( browser == "Netscape" )
document.captureEvents( Event.MOUSEDOWN );
}
</script>
<%
pic = "picture.jpg"
Set objFileSystem = Server.CreateObject("Scrip ting.FileS ystemObjec t")
Set objFile = objFileSystem.GetFile(Serv er.mapPath (pic))
Set objStream = objFile.OpenAsTextStream(1 , TristateTrue)
Response.ContentType = "image/jpeg"
Response.AddHeader "content-length", objFile.Size
Do While Not objStream.AtEndOfStream
char = chrB(asc(objStream.Read(1) )) 'converting unicode to single Byte
Response.BinaryWrite(char)
Loop
%>
If the buffers line is removed -
Response object error 'ASP 0156 : 80004005'
Header Error
/sunscripts/aj/pic.asp, line 68
The HTTP headers are already written to the client browser. Any HTTP header modifications must be made before writing page content
is displayed..
I appreciate your help..
AJ
Here is how I've pieced it together -
<% Response.Buffer = True %>
<script language="JavaScript">
window.onload = trap_page_mouse_key_events
</script>
<script language="JavaScript">
function disable_right_click(e)
{
var browser = navigator.appName.substrin
var event_number = 0;
if (browser=="Microsoft")
event_number = event.button;
else if (browser=="Netscape")
event_number = e.which;
if ( event_number==2 || event_number==3 )
{
alert ("Right Mouse Button Is Disabled");
return (false);
}
return (true);
}
function check_mousekey ()
{
var mouse_key = 93;
var keycode = event.keyCode;
if ( keycode == mouse_key )
alert ( "Mouse Key Is Disabled" );
}
function trap_page_mouse_key_events
{
var browser = navigator.appName.substrin
document.onmousedown = disable_right_click;
if ( browser == "Microsoft" )
document.onkeydown = check_mousekey;
else if ( browser == "Netscape" )
document.captureEvents( Event.MOUSEDOWN );
}
</script>
<%
pic = "picture.jpg"
Set objFileSystem = Server.CreateObject("Scrip
Set objFile = objFileSystem.GetFile(Serv
Set objStream = objFile.OpenAsTextStream(1
Response.ContentType = "image/jpeg"
Response.AddHeader "content-length", objFile.Size
Do While Not objStream.AtEndOfStream
char = chrB(asc(objStream.Read(1)
Response.BinaryWrite(char)
Loop
%>
If the buffers line is removed -
Response object error 'ASP 0156 : 80004005'
Header Error
/sunscripts/aj/pic.asp, line 68
The HTTP headers are already written to the client browser. Any HTTP header modifications must be made before writing page content
is displayed..
I appreciate your help..
AJ
ajosephson,
Some of these questions have been open for some time. Please resolve them appropriately as soon as possible.
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20056728
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20066170 (locked)
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20094993
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20155903
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11866699
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20158889
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20178767
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20179790
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20186684
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20229069
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20241406
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20249663
Thanks,
Netminder
Community Support Moderator
Experts Exchange
Some of these questions have been open for some time. Please resolve them appropriately as soon as possible.
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20056728
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20066170 (locked)
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20094993
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20155903
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11866699
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20158889
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20178767
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20179790
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20186684
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20229069
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20241406
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20249663
Thanks,
Netminder
Community Support Moderator
Experts Exchange
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Points refunded and question closed.
Netminder
Community Support Moderator
Experts Exchange
Netminder
Community Support Moderator
Experts Exchange