简体   繁体   中英

How to detect clicked word in textarea with right click and show menu items from php sql database in in context menu in return of clicked word

We want to design roman transliteration with same pattern of google translation in this regard plz help us. We want two text boxes (Textareas) in one text box user write some text and click a button then the data will be transliterated in other box till this point its easy but we want user can change trnasliterated word with right click menu with various options. this is same like spell checker.

As your OP doesn't provide any detailed information on what you have tried already and what kind of research you've done, I'll just provide you with the basics.

You need to use the "oncontextmenu" event (in the HTML textarea) to trigger the design of your own right-click context menu. I'd query the database via AJAX so that the results can be shown in your menu without having the page reloaded.

There are tons of AJAX tutorials in the internet, so I will give you a hint for the JS function to handle the contextmenu. To design a custom one you can try something like this:

if (document.addEventListener) 
{
    document.addEventListener('contextmenu', function(e) 
    {
        // Design your own menu here
        e.preventDefault();
    }, false);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM