D4llower Posted January 26, 2008 Share Posted January 26, 2008 How to disable right click in the WebBrowser Object ? Somtimes I don't want somebody to open the contextmenu in the WebBrowser... There's some code in Visual Basic: Rem Dim WithEvents M_Dom As MSHTML.HTMLDocument Private Function M_Dom_oncontextmenu() As Boolean M_Dom_oncontextmenu = False End Function Private Sub Webbrowser1_DownloadComplete() Set M_Dom = Webbrowser1.Document End Sub Rem But I don't know whether it will work, or how to change it to au3 script... I need some help... Link to comment Share on other sites More sharing options...
erezlevi Posted January 26, 2008 Share Posted January 26, 2008 good one. I couldn't find anything about it on _IE.au3, can somelse help here. where are the modorators this days???? Link to comment Share on other sites More sharing options...
Squirrely1 Posted January 26, 2008 Share Posted January 26, 2008 How to disable right click in the WebBrowser Object ?I think there is a way to disable the context menu of a web page using Javascript, but you would have to know the author of the web page or be the author. Das Häschen benutzt Radar Link to comment Share on other sites More sharing options...
Richard Robertson Posted January 26, 2008 Share Posted January 26, 2008 If you felt like injecting some javascript into every page after it loads, that'd work. Link to comment Share on other sites More sharing options...
D4llower Posted January 26, 2008 Author Share Posted January 26, 2008 I think there is a way to disable the context menu of a web page using Javascript, but you would have to know the author of the web page or be the author.I have a way that to inject the java script into the HTML from _IEBodyReadHTML() by _IEDocInsertHTML.But what I want now is the way to disable all the context menu in my WebBrowser... Link to comment Share on other sites More sharing options...
D4llower Posted January 26, 2008 Author Share Posted January 26, 2008 If you felt like injecting some javascript into every page after it loads, that'd work.Yeah, but too tedious... Link to comment Share on other sites More sharing options...
Squirrely1 Posted January 26, 2008 Share Posted January 26, 2008 I think at this point, it would take GaryFrost or Valik or some extreme techie to get interested in tackling this challenge. I doubt that it will happen. Das Häschen benutzt Radar Link to comment Share on other sites More sharing options...
weaponx Posted January 26, 2008 Share Posted January 26, 2008 I think at this point, it would take GaryFrost or Valik or some extreme techie to get interested in tackling this challenge. I doubt that it will happen.Your answer is here:http://www.autoitscript.com/forum/index.ph...e++right++click Link to comment Share on other sites More sharing options...
Squirrely1 Posted January 26, 2008 Share Posted January 26, 2008 Your answer is here:http://www.autoitscript.com/forum/index.ph...e++right++clickBy Jove, they've done it. Where are those meta-techie's when I ever need one? Das Häschen benutzt Radar Link to comment Share on other sites More sharing options...
Nahuel Posted January 26, 2008 Share Posted January 26, 2008 By Jove, they've done it. Where are those meta-techie's when I ever need one?Meta-what? Link to comment Share on other sites More sharing options...
Squirrely1 Posted January 27, 2008 Share Posted January 27, 2008 Hey scripting guy, now that this problem is solved, what can you do to get thru to this guy: http://www.autoitscript.com/forum/index.php?showtopic=62726 Das Häschen benutzt Radar Link to comment Share on other sites More sharing options...
D4llower Posted January 27, 2008 Author Share Posted January 27, 2008 Thank you for all of you! But I have to say that I had already know the way of Java script injecting. The weakness of injecting is that you must inject every page in your WebBrowser, include some link you sometimes really can't anticipate it... Is there any efficient way to disable right click? Perhaps call the "WBCustomizer.dll", or use the "IDocHostUIHandler"? But how to use these difficult method? Link to comment Share on other sites More sharing options...
weaponx Posted January 27, 2008 Share Posted January 27, 2008 Its really easy using AutoIt you just call a function to apply it to every page... Link to comment Share on other sites More sharing options...
DaleHohm Posted January 27, 2008 Share Posted January 27, 2008 It's not so hard... make it event-driven: ; Set up an event sink so that we can trigger on page loads $oEvent = ObjEvent($oIE, "Evt_") Func Evt_onload() ; This function will be fired whenever a new page loads _IEHeadInsertEventScript ($oIE, "document", "oncontextmenu", "alert('You cannot rightclick');return false") EndFunc ;==>Evt_onload Dale Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model Automate input type=file (Related) Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded Better Better? IE.au3 issues with Vista - Workarounds SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead? Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble Link to comment Share on other sites More sharing options...
D4llower Posted January 27, 2008 Author Share Posted January 27, 2008 (edited) I've got an idea, but at the sametime I found a problem which possibly the BUG of Function _IsPressed Here is my code: #include <GUIConstants.au3> #include <IE.au3> #Include <Misc.au3> _IEErrorHandlerRegister() $IEobject = _IECreateEmbedded() GUICreate("Disable Right Click In WebBrowser - By D4llower", 640, 400, (@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS) $GUIActiveX = GUICtrlCreateObj($IEobject, 20, 20, 600, 360) GUISetState() _IENavigate($IEobject, "http://www.google.com") _IEHeadInsertEventScript($IEobject, "document", "oncontextmenu", "window.event.cancelBubble = true;window.event.returnValue = false;") While 1 If _IsPressed('01') = 1 Or _ ;Detect the Left mouse button _IsPressed('02') = 1 Or _ ;Detect the Right mouse button _IsPressed('04') = 1 Or _ ;Detect the Middle mouse button (three-button mouse) _IsPressed('05') = 1 Or _ ;Detect the Windows 2000/XP: X1 mouse button _IsPressed('06') = 1 Or _ ;Detect the Windows 2000/XP: X2 mouse button _IsPressed('A4') = 1 Or _ ;Detect the Left MENU key, but Not work, Bug ??? _IsPressed('A5') = 1 Then ;Detect the Right MENU key, but Not work, Bug ??? _IEHeadInsertEventScript($IEobject, "document", "oncontextmenu", "window.event.cancelBubble = true;window.event.returnValue = false;") ;Inject Java Script... EndIf $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop EndSelect WEnd Exit I feel it not bad. But why _IsPressed can't detect the MENU key in keyboard, I mean when I click into some new page, or there is something wrong with my code ? Edited January 27, 2008 by D4llower Link to comment Share on other sites More sharing options...
D4llower Posted January 27, 2008 Author Share Posted January 27, 2008 (edited) It's not so hard... make it event-driven: ; Set up an event sink so that we can trigger on page loads $oEvent = ObjEvent($oIE, "Evt_") Func Evt_onload() ; This function will be fired whenever a new page loads _IEHeadInsertEventScript ($oIE, "document", "oncontextmenu", "alert('You cannot rightclick');return false") EndFunc ;==>Evt_onload Dale Thanks, but actually it doesn't work...??? Can you try it and tell me the result? Edited January 27, 2008 by D4llower Link to comment Share on other sites More sharing options...
DaleHohm Posted January 27, 2008 Share Posted January 27, 2008 No, you try it and show what you did and try to figure out why it didn't work. Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model Automate input type=file (Related) Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded Better Better? IE.au3 issues with Vista - Workarounds SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead? Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble Link to comment Share on other sites More sharing options...
intime69 Posted December 5, 2010 Share Posted December 5, 2010 (edited) How to disable right click in the WebBrowser Object ? Here's the best way that I found and it actually works very well: If $msg = $GUI_EVENT_SECONDARYDOWN or $msg = $GUI_EVENT_PRIMARYDOWN or $GUI_EVENT_PRIMARYUP Then _IEHeadInsertEventScript ($ieo, "document", "oncontextmenu", "return false") Endif This detects mouse clicks just as the page loads and disables the context menu on any new loaded page. Let me know if it works at your end and sorry for replying on a subject that is quite old. It took me several hours to finally figure out how to get this completely working. There was a similar answer but it didn't always work because only $GUI_EVENT_PRIMARYDOWN was used. All 3 are required. Cheers, Ian Edited December 5, 2010 by intime69 Developer and Co-OwnerInTime Applicaitons Inc. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now