parent
9557bdb01e
commit
2d7a27c8af
@ -0,0 +1,10 @@
|
|||||||
|
<ul id="rcb_menu">
|
||||||
|
<li id="rcb_t1">🏠 首页</li>
|
||||||
|
<li class="hr_break"></li>
|
||||||
|
<li id="rcb_t2">↑ 页顶</li>
|
||||||
|
<li id="rcb_t3">↩ 返回</li>
|
||||||
|
<li id="rcb_t4">↪ 前进</li>
|
||||||
|
<li id="rcb_t5">↻ 重载</li>
|
||||||
|
<li id="rcb_t6">🆕 新标签页打开</li>
|
||||||
|
</ul>
|
||||||
|
<script src="https://tools.pj568.eu.org/js/contextmenu.js"></script>
|
@ -0,0 +1,50 @@
|
|||||||
|
window.addEventListener('contextmenu', RightClickMenu);
|
||||||
|
const rightMenu = document.querySelector('#rcb_menu');
|
||||||
|
const newTab = document.querySelector('#rcb_t6');
|
||||||
|
function RightClickMenu(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
rightMenu.style.display = 'block';
|
||||||
|
if (e.target.closest('a')) {
|
||||||
|
newTab.style.display = 'block';
|
||||||
|
} else {
|
||||||
|
newTab.style.display = 'none';
|
||||||
|
}
|
||||||
|
let x = e.clientX, y = e.clientY,
|
||||||
|
menuWidth = rightMenu.offsetWidth, menuHeight = rightMenu.offsetHeight,
|
||||||
|
htmlWidth = document.body.clientWidth, htmlHeight = document.body.clientHeight;
|
||||||
|
if (x + menuWidth < htmlWidth) rightMenu.style.left = x + 'px';
|
||||||
|
else rightMenu.style.left = htmlWidth - menuWidth + 'px';
|
||||||
|
if (y + menuHeight < htmlHeight) rightMenu.style.top = y + 'px';
|
||||||
|
else rightMenu.style.top = htmlHeight - menuHeight + "px";
|
||||||
|
}
|
||||||
|
document.body.addEventListener('click', function () {
|
||||||
|
rightMenu.style.display = 'none';
|
||||||
|
});
|
||||||
|
// document.querySelector('#rcb_menu').addEventListener('click', function (e) {
|
||||||
|
rightMenu.addEventListener('click', function (e) {
|
||||||
|
switch (e.target.id) {
|
||||||
|
case "rcb_t1":
|
||||||
|
window.location.href="temp.html";
|
||||||
|
break;
|
||||||
|
case "rcb_t2":
|
||||||
|
window.location.href="#";
|
||||||
|
break;
|
||||||
|
case "rcb_t3":
|
||||||
|
window.history.back(-1);
|
||||||
|
break;
|
||||||
|
case "rcb_t4":
|
||||||
|
window.history.forward(1);
|
||||||
|
break;
|
||||||
|
case "rcb_t5":
|
||||||
|
window.location.reload();
|
||||||
|
break;
|
||||||
|
case "rcb_t6":
|
||||||
|
if (e.target.closest('.open-in-new-tab')) {
|
||||||
|
window.open(e.target.closest('.open-in-new-tab').getAttribute('href'), '_blank');
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
console.error(e.target.id);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
});
|
Loading…
Reference in new issue