当前位置:网站首页>Customize browser default right-click menu bar
Customize browser default right-click menu bar
2022-07-26 12:14:00 【Good at learning】
This article briefly introduces How to change the browser's default right-click menu bar
Right click anywhere on the page , Customized menus will be displayed according to the click position of the mouse
design sketch :

Don't talk much , Go straight to the code !
<!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> Enhanced custom menu </title>
<style>
* {
padding: 0;
margin: 0;
}
ul {
width: 230px;
background-color: rgb(255, 255, 255);
position: fixed;
left: 100px;
top: 100px;
border: 1px solid rgb(105, 105, 105);
padding-top: 10px;
text-indent: 10px;
list-style: none;
display: none;
}
li{
margin-bottom: 13px;
color: #000;
font: 800 16px/26px " Song style ";
border-bottom: 1px solid #ccc;
}
li:last-child{
border-bottom: none;
margin-bottom: 0;
padding-bottom: 5px;
}
li:hover{
background-color: rgb(69, 255, 193);
box-shadow: 0px 0px 26px 0px rgb(69, 255, 193);
}
ul li:first-child:hover{
background-color: rgb(91, 230, 255);
box-shadow: 0px 0px 26px 0px rgb(91, 230, 255);
}
</style>
</head>
<body>
<!-- 2. Enhanced custom menu 【√】
· When you click the right mouse button, a custom menu pops up ( Cultivate one's morality , To put , Governing the , Flat world )
· When the menu item is clicked log Check the menu name , After the menu... Disappears
· Which menu item is highlighted when the mouse is over -->
<ul>
<li id="Refresh"> Refresh (F5)</li>
<li> Cultivate one's morality (s)</li>
<li> To put (q)</li>
<li> Governing the (z)</li>
<li> Flat world (p)</li>
</ul>
<script>
var ul = document.querySelector("ul")
var lis = document.querySelectorAll("li")
var F5 = document.getElementById("Refresh")
// var Rclick = document.oncontextmenu()
// Block the default behavior of the browser's right-click pop-up list
document.addEventListener(
"contextmenu",
function(e){
e.preventDefault()
ul.style.display = "block"
ul.style.left = e.pageX + "px"
ul.style.top = e.pageY + "px"
}
)
// Achieve click li Menu item log Check the menu name , And which menu item the mouse is over, which menu item is highlighted
ul.addEventListener(
"click",
function(e){
if(e.target.nodeName === "LI"){
console.log(e.target.innerText);
ul.style.display = "none"
}
}
)
// Implement refresh button
F5.addEventListener(
"click",
function(e){
window.location.reload()
}
)
// Click anywhere on the page to close ul
document.addEventListener(
"click",
(e)=>{
ul.style.display = "none"
}
)
</script>
</body>
</html>边栏推荐
- 什么是Per-Title编码?
- 《多线程下ThreadLocal使用场景实例》
- Network protocol: tcp/ip protocol
- Why is redis so fast? Redis threading model and redis multithreading
- Pytest interface automation test framework | rerun failed cases
- Pytest interface automated test framework | fixture call fixture
- Pytest interface automation test framework | pytest configuration file
- 网络协议:TCP/IP协议
- 大佬们,请教一下,我按照文档配了cdc连接oracle,总是运行报错找不到类 ValidstionE
- Yuancosmos daily | yuancosmos social app "Party Island" product off the shelves; Guangzhou Nansha yuanuniverse industrial agglomeration zone was unveiled; The inter ministerial joint conference system
猜你喜欢
随机推荐
行业案例|指标中台如何助力银行业普惠金融可持续发展
代码实例详解【可重入锁】和【不可重入锁】区别?
【Map】万能的Map使用方法 & 模糊查询的两种方式
Access数据库无法连接
Flink cdc 是不是只支持 sql-client的方式提交SQL脚本啊
pytest接口自动化测试框架 | pytest常用插件
Introduction to FPGA (I) - the first FPGA project
What is oom, why it happens and some solutions
数智转型,管理先行|JNPF全力打造“全生命周期管理”平台
结合环境光、接近传感以及红外测距的光距感芯片4530A
Dry goods semantic web, Web3.0, Web3, metauniverse, these concepts are still confused? (medium)
剑指 Offer 24. 反转链表
Is it easy to find a job after programmer training?
二、容器_
什么是OOM,为什么会OOM及一些解决方法
Y9000p2022 reinstallation win10 problem
【活动早知道】LiveVideoStack近期活动一览
On the construction and management of low code technology in logistics transportation platform
面试官:如何处理高并发?
Pytest interface automated testing framework | common plug-ins of pytest









