源代码:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Fmpq教程(fmpq.com)</title> <style> div { background: yellow; border: 1px solid #cccccc; padding: 10px; } </style> </head> <body> <div contextmenu="mymenu"> <p>用鼠标右键单击黄色框区域查看上下文菜单</p> <menu type="context" id="mymenu" onshow="myFunction()"> <menuitem label="Refresh" onclick="window.location.reload();" icon="ico_reload.png"></menuitem> <menu label="分享..."> <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="发邮件到该页面" onclick="window.location='mailto:?body='+window.location.href;"></menuitem> </menu> </div> <p><strong>注意:</strong>目前只有 Firefox 浏览器支持 onshow 属性。</p> <script> function myFunction() { alert("上下文菜单即将显示"); } </script> </body> </html>
运行结果:
Fmpq工具