Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Contributor
Posts: 34
Registered: ‎12-20-2010
My Device: DevAlpha Beta 2
My Carrier: Orange

Disable Actions on WebView long clics

Hello,

 

Does anyone know how to disable the action menu that opens when long clicking a link or an image on a WebView ?

 

Thank you!

Contributor
Posts: 34
Registered: ‎12-20-2010
My Device: DevAlpha Beta 2
My Carrier: Orange

Re: Disable Actions on WebView long clics

OK, here is the solution :

 

WebView {

        id: webContent

        onLoadingChanged: {

              if(loadRequest.status == WebLoadStatus.Succeeded) {

                      // following script disables context menu for all document elements in a web page

                      // oncontextmenu event is not a standard but is handled by WebView and most popular webbrowsers

                       evaluateJavaScript(

                             "navigator.cascades.postMessage(\"Number of images on page: \" + document.images.length);" +

                             "function disableContextMenu(e) {" +

                                    "if(e.preventDefault) {" +

                                           "e.preventDefault();" +

                                    "}" +

                                    "if(e.stopPropagation) {" +

                                          "e.stopPropagation()" +

                                    "}" +

                                    "e.returnValue=false;" +

                             "}" +

                            "document.oncontextmenu=disableContextMenu;"

                       );

               }

        }

}