Context Menu

ContextMenu
A pop-up menu triggered by a right mouse click (Windows, Linux, etc), or control-click (Mac).

The idea is that your graphical objects are nouns and the context menu provides appropriate verbs (NounsAndVerbs), very similar to messages to an object. This a common UserInterfacePattern? also seen in SmalltalkLanguage and NakedObjects.


Q: How does one create a ContextMenu for a Web application?

A: Use JavaScript. An example (for InternetExplorer) is given at http://javascript.internet.com/page-details/right-click-menu.html.

It's claimed that if you use Netscape, you need at least Netscape 6. An example for NS6 (or IE5+) is given at http://www.dynamicdrive.com/dynamicindex1/contextmenu.htm.

Q: Why can't I create a ContextMenu for a Web application in PHP/CeeLanguage/MySql/etc?

A: Bringing up a context menu must be done in JavaScript because by the time the browser gets the page, PHP & MySql are no longer part of the picture. A browser requests a Web page from a server; the server uses PHP and MySql to build the page. Once the page is built, PHP & MySql's job is done. Anything that happens once the page is returned (e.g., activating a context menu) must be done on the browser side. That means JavaLanguage, JavaScript, MacromediaFlash, etc. Check out any book on Web app development if this isn't clear.


You can conditionally output JavaScript with PHP though. eg.

    function js_alert($msg) {
        ?>
        <script type="text/javascript">
            <!--
            alert('<?php echo $msg; ?>');
            -->
        </script>
        <?php
        exit;
    }

Sloppy as hell, but it works, and points out why PHP is a Hypertext Preprocessor. Something similar could be done using PHP to build the menu then use Javascript to fire the event.


EditText of this page (last edited October 11, 2012) or FindPage with title or text search