用js实现网页上模仿桌面右键菜单
网页上模仿桌面右键菜单
右击鼠标看看 -_-!
\n";
// rbpm = right button pop menu
HTMLstr += "
\n";
HTMLstr += "
\n";
HTMLstr += "";
HTMLstr += "\n";
HTMLstr += "\n";
}
function AddExtendMenu(id,name,parent)
{
var TempStr = "";
eval("A_"+parent+".length++");
eval("A_"+parent+"[A_"+parent+".length-1] = id"); // 将此项注册到父菜单项的ID数组中去
TempStr += "
\n";
TempStr += "
\n";
TempStr += "
\n";
TempStr += "";
TempStr += "";
HTMLstr = HTMLstr.replace("",TempStr);
eval("A_"+id+" = new Array()");
TempStr = "";
TempStr += "\n";
TempStr += "
TempStr += " "+name+"
TempStr += "
\n";
TempStr += "";
HTMLstr = HTMLstr.replace("",TempStr);
}
function AddItem(id,name,parent,location)
{
var TempStr = "";
var ItemStr = "";
if(id == "sperator")
{
TempStr += ItemStr+"\n";
TempStr += "
";
TempStr += "";
HTMLstr = HTMLstr.replace("",TempStr);
return;
}
if(HTMLstr.indexOf(ItemStr) != -1)
{
alert("I_"+id+"already exist!");
return;
}
TempStr += ItemStr+"\n";
TempStr += "
TempStr += " "+name+" ";
TempStr += "
\n";
TempStr += "";
HTMLstr = HTMLstr.replace("",TempStr);
}
function GetMenu()
{
return HTMLstr;
}
function I_OnMouseOver(id,parent)
{
var Item;
if(parent != "rbpm")
{
var ParentItem;
ParentItem = eval("P_"+parent);
ParentItem.className="over";
}
Item = eval("I_"+id);
Item.className="over";
HideAll(parent,1);
}
function I_OnMouseOut(id)
{
var Item;
Item = eval("I_"+id);
Item.className="out";
}
function I_OnMouseUp(id,parent,location)
{
var ParentMenu;
window.event.cancelBubble=true;
OnClick();
ParentMenu = eval("E_"+parent);
ParentMenu.display="none";
if(location == null)
eval("Do_"+id+"()");
else
window.open(location);
}
function P_OnMouseOver(id,parent)
{
var Item;
var Extend;
var Parent;
if(parent != "rbpm")
{
var ParentItem;
ParentItem = eval("P_"+parent);
ParentItem.className="over";
}
HideAll(parent,1);
Item = eval("P_"+id);
Extend = eval("E_"+id);
Parent = eval("E_"+parent);
Item.className="over";
Extend.style.display="block";
Extend.style.posLeft=document.body.scrollLeft+Parent.offsetLeft+Parent.offsetWidth-4;
if(Extend.style.posLeft+Extend.offsetWidth > document.body.scrollLeft+document.body.clientWidth)
Extend.style.posLeft=Extend.style.posLeft-Parent.offsetWidth-Extend.offsetWidth+8;
if(Extend.style.posLeft document.body.scrollTop+document.body.clientHeight)
Extend.style.posTop=document.body.scrollTop+document.body.clientHeight-Extend.offsetHeight;
if(Extend.style.posTop document.body.scrollLeft+document.body.clientWidth)
PopMenu.style.posLeft=document.body.scrollLeft+document.body.clientWidth-PopMenu.offsetWidth;
if(PopMenu.style.posLeft document.body.scrollTop+document.body.clientHeight)
PopMenu.style.posTop=document.body.scrollTop+document.body.clientHeight-PopMenu.offsetHeight;
if(PopMenu.style.posTop
C)...","rbpm",null);
menu.AddItem("refresh"," 刷新","rbpm",null);
menu.AddItem("sperator","","rbpm",null);
menu.AddItem("phase"," 粘贴 CTRL+Z","rbpm",null);
menu.AddExtendMenu("n_files"," 新建","rbpm");
menu.AddItem("f_folder","文件夹","n_files","http://www.cctv.com/");
menu.AddItem("shortcut","快捷方式","n_files","http://www.cctv.com/");
menu.AddItem("sperator","","n_files","");
menu.AddItem("f_txt","Microsoft Word 文档","n_files","http://www.cctv.com/");
menu.AddItem("f_htm","Microsoft Excel 工作表","n_files","http://www.cctv.com/");
menu.AddItem("sperator","","rbpm",null);
menu.AddItem("folder_pro"," 属性","rbpm",null);
document.writeln(menu.GetMenu());
-->
[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]