程式碼如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<頭>
<TITLE>Popup物件實作右鍵選單</TITLE>
<腳本語言=“JavaScript”>
var oPopup = window.createPopup();
函數上下文選單()
{
var left = event.offsetX+10;
var top = event.offsetY+10;
oPopup.document.body.innerHTML = oContext.innerHTML;
oPopup.show(左, 上, 120, 80, window.document.body);
}
</腳本>
</頭>
<body oncontextmenu="contextMenu(); 回傳 false;">
<h1>Popup物件實作右鍵選單</h1>
點選滑鼠右鍵查看效果
<div ID="oContext" style="顯示:無;背景:#e4e4e4;">
<div onmouseover="this.style.background='金色'"
onmouseout="this.style.background='#e4e4e4'"
<span onclick='parent.location.href=" http://www.zol.com.cn"' >
中關村線上</span>
</div>
<div onmouseover="this.style.background='金色'"
onmouseout="this.style.background='#e4e4e4'"
<span onclick="parent.location.href='http://www.cfan.com.cn'">
電腦愛好者</span>
</div>
<div onmouseover="this.style.background='金色';"
onmouseout="this.style.background='#e4e4e4';">
<span onclick="parent.location.href='http://www.sina.com.cn'">
新浪網</span>
</div>
<div onmouseover="this.style.background='金色'"
onmouseout="this.style.background='#e4e4e4'"
<span onclick="parent.location.href='http://www.xinhuanet.com'">
新華網</span>
</div>
</div>
</正文>
</html>