源代码
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>编程字典</title> <style> div { background: yellow; border: 1px solid black; padding: 10px; } </style> </head> <body> <div contextmenu="mymenu"> <p>在这个框里右键单击,可以显示一个上下文菜单。 <menu type="context" id="mymenu"> <menuitem label="Refresh" onclick="window.location.reload();" icon="ico_reload.png"></menuitem> <menu label="Share on..."> <menuitem label="Twitter" icon="ico_twitter.png" onclick="window.open('//twitter.com/intent/tweet?text=' + window.location.href);"></menuitem> <menuitem label="Facebook" icon="ico_facebook.png" onclick="window.open('//facebook.com/sharer/sharer.php?u=' + window.location.href);"></menuitem> </menu> <menuitem label="Email This Page" onclick="window.location='mailto:?body='+window.location.href;"></menuitem> </menu> </div> <p>这个实例只能在Firefox中生效!</p> </body> </html>
运行结果