0

If I would like a menu to pop up automatically just as I select the text (no further clicking is needed), what method could be one of the choices? Thank you!

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
Paragraph 1: In the seventeenth and eighteenth centuries, the British parliament enacted a number of laws, called Navigation Acts, governing commerce between Britain and its oversea colonies. For example, the Navigation Acts of 1600 and 1603 barred the empire’s colonial merchants from exporting such commodities as sugar and tobacco anywhere except to England and from importing goods in non-English ships. Similarly, the Mollases Act of 1733 taxed all foreign mollases (a thick liquid drained from sugarcane and used to make rum) entering the mainland American colonies at sixpence per gallon. This act was intended less to raise revenue than to serve as protective tariff (tax) than would benefit British West Indian sugar producers at the expenses of their French rivals. By 1750 a long series of Navigation Acts were in force, with several effects on the North American colonial economy.
</body>
</html>

enter image description here

1 Answers1

1

You can use this:

Just change the alert part to whatever you wanna do

var t = '';
function gText(e) {
    t = (document.all) ? document.selection.createRange().text : document.getSelection();
        if (t == "raise revenue" || t == " raise revenue" || t == "raise revenue " || t == " raise revenue ") {
            alert("Popped UP!!!")
    }
    
}

document.onmouseup = gText;
if (!document.all) document.captureEvents(Event.MOUSEUP);
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
Paragraph 1: In the seventeenth and eighteenth centuries, the British parliament enacted a number of laws, called Navigation Acts, governing commerce between Britain and its oversea colonies. For example, the Navigation Acts of 1600 and 1603 barred the empire’s colonial merchants from exporting such commodities as sugar and tobacco anywhere except to England and from importing goods in non-English ships. Similarly, the Mollases Act of 1733 taxed all foreign mollases (a thick liquid drained from sugarcane and used to make rum) entering the mainland American colonies at sixpence per gallon. This act was intended less to raise revenue than to serve as protective tariff (tax) than would benefit British West Indian sugar producers at the expenses of their French rivals. By 1750 a long series of Navigation Acts were in force, with several effects on the North American colonial economy.
</body>
</html>

Modified Robert's answer to suit your problem

spadletskys
  • 125
  • 7