Disable context menu in browser

Post here questions and problems related to editing and publishing DITA content.
Jeff_Reynolds
Posts: 37
Joined: Tue Apr 13, 2021 9:48 pm

Disable context menu in browser

Post by Jeff_Reynolds »

I want to secure the content in WebHelp by disabling Save as...

I think the HTML is

Code: Select all

<html>
<body oncontextmenu="return false;">
</body>
</html>
What has to happen in XML source, can I set an xform attribute?
beniamin_savu
Posts: 30
Joined: Fri Jan 22, 2021 11:05 am

Re: Disable context menu in browser

Post by beniamin_savu »

Hi,

There are 2 possible solutions to add the oncontextmenu attribute on the <body> element.

1. Adding the attribute using XSLT extension point:
* Create a custom publishing template
* In the custom publishing template folder create a folder named xsl
* In the xsl folder create a xsl file, for example disable-context-menu.xsl.
* Add in the xsl file the following template:

Code: Select all

<xsl:template match="*:body[contains(@class, 'wh_topic_page')]" mode="copy_template">
    <xsl:copy copy-namespaces="no">
        <xsl:attribute name="oncontextmenu">return false;</xsl:attribute>
            
        <!-- Apply the default processing -->
        <xsl:next-match/>
    </xsl:copy>        
</xsl:template>
* Open the template descriptor file associated with your publishing template (the .opt file) and set the XSLT stylesheet created in the previous step with the com.oxygenxml.webhelp.xsl.createMainPage XSLT extension point.

Code: Select all

<publishing-template>
    ...
    <webhelp>
        ...
        <xslt>
            <extension 
                file="xslt/disable-context-menu.xsl" 
                id="com.oxygenxml.webhelp.xsl.dita2webhelp"/>
        </xslt>
        ...
    </webhelp>
</publishing-template>
* Run the WebHelp Responsive transformation using the custom publishing template.

Note: An example for this publishing template can be found here using the following link https://github.com/oxygenxml/oxygen-pub ... ntext-menu

2. Adding the attribute by modifying the HTML Page Layout Files:
* Create a custom publishing template and select the Include HTML Page Layout Files.
* In your custom publishing template edit the page-templates/wt_topic.html file and add the attribute oncontextmenu on the <body> element.

Code: Select all

<body class="wh_topic_page" oncontextmenu="return flase;">
* Run the WebHelp Responsive transformation using the custom publishing template.

Best regards,
Beniamin Savu
Oxygen WebHelp Team
http://www.oxygenxml.com
Jeff_Reynolds
Posts: 37
Joined: Tue Apr 13, 2021 9:48 pm

Re: Disable context menu in browser

Post by Jeff_Reynolds »

Thanks for the solution, much appreciated
Post Reply