WebControl and right clicking
WebControl and right clicking
When using the web control, it's great for displaying html and .gif graphics and for page layouts. It's even cool when you can right click and select Print. It's an easy peasy lemon squeezy way of adding printing functionality to a program. The problem is that I don't want View Source, or Add to Favorites or some of the other features to be selected. Is their a way to limit the options a user can select when right clicking in the pop up over a webcontrol?
Re: WebControl and right clicking
Use javascript:
<SCRIPT language=JavaScript>
// No rightclick script for IE
function click()
{
if (event.button==2)
{
alert('NO RIGHT CLICKING ALLOWED');
}
}
document.onmousedown=click
</SCRIPT>
<SCRIPT language=JavaScript>
// No rightclick script for Netscape
if (navigator.appName.indexOf("Netscape") != -1){
window.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP)
window.onmousedown=rightclick;
window.onmouseup=rightclick;
function rightclick(e) {
if (e.which == 3) {
alert('NO RIGHT CLICKING ALLOWED')
return false;
}
else {
return true;
}
}
}
</SCRIPT>
<SCRIPT language=JavaScript>
// No rightclick script for IE
function click()
{
if (event.button==2)
{
alert('NO RIGHT CLICKING ALLOWED');
}
}
document.onmousedown=click
</SCRIPT>
<SCRIPT language=JavaScript>
// No rightclick script for Netscape
if (navigator.appName.indexOf("Netscape") != -1){
window.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP)
window.onmousedown=rightclick;
window.onmouseup=rightclick;
function rightclick(e) {
if (e.which == 3) {
alert('NO RIGHT CLICKING ALLOWED')
return false;
}
else {
return true;
}
}
}
</SCRIPT>
ARGENTINA WORLD CHAMPION
If you just want to print from the WebGadget just write a small html file, then display it in the WebGadget. To get the functionality of the print just use simple javascript to add or remove features, i.e.:
use a button for printing:
or use a hyperlink for printing:
To disable the pop-up context menu place this code in the <head> and <body> sections respectively:
use a button for printing:
Code: Select all
<input type="button" name="Print" onClick="window.print();">
Code: Select all
<a href="javascript:void(0)">Click Me To Print</a onClick="window.print();">
Code: Select all
<head>
<script language="javascript">
function AltDown() {
if (event.keyCode==122) {
alert("The F11 is not supported");
event.returnValue=false;
event.keyCode=0;
}
if (event.keyCode==116) {
alert("The F5 is not supported");
event.returnValue=false;
event.keyCode=0;
}
if (event.keyCode==27) {
alert("The ESC is not supported");
event.returnValue=false;
event.keyCode=0;
}
if (event.altKey) {
alert("The Alt Key is not supported");
}
if (event.ctrlKey) {
alert("The Ctrl Key is not supported");
}
if (event.shiftKey) {
alert("The Shift Key is not supported");
}
}
var isnn,isie
if (navigator.appName=='Microsoft Internet Explorer') {
isie=true;
}
if (navigator.appName=='Netscape') {
isnn=true;
}
function right(e) {
if (isnn && (e.which == 3 || e.which == 2 )) {
return false;
}
else if (isie && (event.button == 2 || event.button == 3)) {
return false;
}
return true;
}
function key(k) {
if (isie) {
if (event.keyCode==116) {
event.returnValue=false;
}
if (event.keyCode==16 || event.keyCode==17 || event.keyCode==18 ||event.keyCode==93) {
return false;
}
}
if (isnn) {
alert("Sorry, you do not have permission to press this key.")
return false;
}
}
if (document.layers) {window.captureEvents(Event.KEYPRESS);}
if (document.layers) {window.captureEvents(Event.MOUSEDOWN);}
if (document.layers) {window.captureEvents(Event.MOUSEUP);}
document.onkeydown=key;
document.onmousedown=right;
document.onmouseup=right;
window.document.layers=right;
window.onerror = null;
</script>
</head>
<body onKeyDown="AltDown();" oncontextmenu="return false" onselectstart="return false" ondragstart="return false">
What if Java code is already in the web control, like...
The Java script commands do not work because Java code is already running in the web control.
Last edited by LJ on Fri Aug 01, 2003 3:34 pm, edited 1 time in total.
No API
No API commands, my eyes are bugging out searching and reading through all the documentation. Thanks for all the suggestions. I still can't believe that there is not a way to insert some of the java code you guys gave me into the code I posted above. Will keep you all posted if I can figure this out. Thanks again for the java code.
GOT IT!!!
Yeehaw, got it! This line prevents right clicking and text selection in a web control. Not sure about Netscape, but really Netscape should not matter because Purebasic uses the Internet Explorer browser control, ATL.DLL
This single line inserted in the code above in the text output areas, the Feedback function, the Question function, disables text selection and right clicking.
This code works where the java script didn't because it can be planted anywhere (in the BODY), in any frame, on any text (i.e. the contents of a variable are output by Java to the web control) output and it doesn't require a Java script (<script> </script>) nesting so that it can be called inside another Java script with no interference. I tried about 15 different Javascript "No right click" codes, and this was the only bit of code that worked in the Java code I posted above.
Again, thanks for your pointers as I would not have been able to acquire this knowledge if it was not first built upon the knowledge ADN, Kale, and Ricardo shared, thanks guys.
Code: Select all
<body bgcolor="#FFFFFF" text="#000000" oncontextmenu="return false" onselectstart="return false"ondragstart="return false">
This code works where the java script didn't because it can be planted anywhere (in the BODY), in any frame, on any text (i.e. the contents of a variable are output by Java to the web control) output and it doesn't require a Java script (<script> </script>) nesting so that it can be called inside another Java script with no interference. I tried about 15 different Javascript "No right click" codes, and this was the only bit of code that worked in the Java code I posted above.
Again, thanks for your pointers as I would not have been able to acquire this knowledge if it was not first built upon the knowledge ADN, Kale, and Ricardo shared, thanks guys.

Last edited by LJ on Fri Jun 13, 2003 3:17 pm, edited 1 time in total.
Re: GOT IT!!!
But if you go from an Activex you can catch the click and do watever you want...
ARGENTINA WORLD CHAMPION
hi LJ,
I've just coded an example that shows how to disable right clicking and selecting the content of a file using API-commands.
I hope you'll understand it
For now it works good, but I've only one problem:
How can I detect whether the browser-window contains scrollbars or not.
In this version you must be sure whether they exists, else there is a security hole...
Except you lock them always
Sebi or PureF/\n
I've just coded an example that shows how to disable right clicking and selecting the content of a file using API-commands.
I hope you'll understand it

For now it works good, but I've only one problem:
How can I detect whether the browser-window contains scrollbars or not.
In this version you must be sure whether they exists, else there is a security hole...
Except you lock them always
Code: Select all
Global OldHandler.l
Global H_Scrollbar.l
Global V_Scrollbar.l
Procedure LockWebGadgetCallback(WindowID, Message, wParam, lParam)
If Message=32
MessageRequester("Error!","Right mouse button disabled!",0)
ElseIf Message=528
GetWindowRect_(WindowID,@r.RECT)
vwidth=GetSystemMetrics_(#SM_CXVSCROLL)
hheight=GetSystemMetrics_(#SM_CYHSCROLL)
webwidth=r\right-r\left
webheight=r\bottom-r\top
SI.ScrollInfo
SI\cbSize=SizeOf(ScrollInfo)
X=lParam&$FFFF
Y=lParam>>16
GetCursorPos_(@p.POINT)
hwnd=WindowFromPoint_(p\x,p\y)
If X<webwidth-V_Scrollbar*vwidth
If Y<webheight-H_Scrollbar*hheight
If wParam=513
mouse_event_(#MOUSEEVENTF_LEFTUP,0,0,0,0)
mouse_event_(#MOUSEEVENTF_LEFTUP,0,0,0,0)
ElseIf wParam=516
mouse_event_(#MOUSEEVENTF_RIGHTUP,0,0,0,0)
mouse_event_(#MOUSEEVENTF_RIGHTUP,0,0,0,0)
ElseIf wParam=519
mouse_event_(#MOUSEEVENTF_MIDDLEUP,0,0,0,0)
mouse_event_(#MOUSEEVENTF_MIDDLEUP,0,0,0,0)
EndIf
EndIf
EndIf
EndIf
ProcedureReturn CallFunctionFast(OldHandler, WindowID, Message, wParam, lParam)
EndProcedure
;It locks the webgadget except the selected scrollbars
Procedure LockWebGadget(GadgetNum,Scrollbars)
OldHandler=GetWindowLong_(GadgetID(GadgetNum),#GWL_WNDPROC)
SetWindowLong_(GadgetID(GadgetNum),#GWL_WNDPROC,@LockWebGadgetCallback())
H_Scrollbar=Scrollbars&1
V_Scrollbar=(Scrollbars>>1)&1
EndProcedure
#WEB_HSCROLLBAR=1
#WEB_VSCROLLBAR=2
If OpenWindow(0, 0, 0, 320, 320, #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget, "PureBasic - Gadget Demonstration")
If CreateGadgetList(WindowID())
WebGadget(0, 10, 10, 300, 300, "http://www.purebasic.com")
LockWebGadget(0,#WEB_HSCROLLBAR+#WEB_VSCROLLBAR)
EndIf
Repeat
EventID = WaitWindowEvent()
Until EventID = #PB_EventCloseWindow
EndIf
End
Re: GOT IT!!!
@LJ
Small is butyfull
Thanks for sharing this one !
Code: Select all
<body bgcolor="#FFFFFF" text="#000000" oncontextmenu="return false" onselectstart="return false"ondragstart="return false">

Thanks for sharing this one !
Why thank you...
Thank you very much. I believe your comment, from another programmer, referencing my code to be beautiful as the highest of compliments.
I once had an Algebra instructor who would create beautiful algorithms and functions on a chalkboard. He once told me: "Lance, when you get to the level, in any discipline, when you can see beauty in various solutions, you will then know how to create beautiful solutions yourself."
Well, it sounded better when he said it.
I look forward to seeing your own beautiful creations in Purebasic.
I once had an Algebra instructor who would create beautiful algorithms and functions on a chalkboard. He once told me: "Lance, when you get to the level, in any discipline, when you can see beauty in various solutions, you will then know how to create beautiful solutions yourself."
Well, it sounded better when he said it.
I look forward to seeing your own beautiful creations in Purebasic.