Forum Moderators: open
<html><head>
<title>Menu test </title>
<script type="text/javascript" src="javamenu.js"></script>
</head>
<body bgcolor="white" text="black" link="blue" vlink="purple" alink="red">
<p> </p>
<a href='#' onclick="vp_Show_Menu('veriu_menu1', this);return false;"><span id="vp_menu_container">Menu test</span></a>
<div id="veriu_menu1" style="display:none">
<table cellpadding="4" cellspacing="1" border="0">
<tr><td style="text-align: left;">Demo Sites</td></tr>
<tr><td style="font-weight: normal; text-align: left;"><a href="#">test1</a></td></tr>
<tr><td style="font-weight: normal; text-align: left;"><a href="#">test2</a></td></tr>
<tr><td style="font-weight: normal; text-align: left;"><a href="#">test3</a></td></tr>
</table>
</div>
</body>
</html>
javamenu.js
var vp_active_Menu = false; function vp_Show_Menu(id,inputObj) if (vp_active_Menu && vp_active_Menu.style.visibility == 'visible') { function vp_Menu_Show(id,inputObj) var leftPos = (vp_Menu_getLeftPos(inputObj) ); vp_active_Menu.style.position = 'absolute'; //vp_active_Menu.onclick = function () {vp_Menu_Hide();} function vp_Menu_Hide(event) { if (is_ie) if (el!= 'vp_menu_container' && vp_active_Menu.style.visibility == 'visible') { } function vp_Menu_getTopPos(inputObj) function vp_Menu_getLeftPos(inputObj) if (!document.addEventListener){
var agt = navigator.userAgent.toLowerCase();
var agt_ver = parseInt(navigator.appVersion);
var is_mozilla = (navigator.product == "Gecko");
var is_opera = (agt.indexOf("opera")!= -1);
var is_konqueror = (agt.indexOf("konqueror")!= -1);
var is_webtv = (agt.indexOf("webtv")!= -1);
var is_ie = ((agt.indexOf("msie")!= -1) && (!is_opera) && (!is_webtv));
var is_netscape = ((agt.indexOf("compatible") == -1) && (agt.indexOf("mozilla")!= -1) && (!is_opera) && (!is_webtv));
var is_win = (agt.indexOf("win"!= -1));
var is_mac = (agt.indexOf("mac")!= -1);
{
vp_active_Menu.style.visibility='hidden';
} else {
vp_Menu_Show(id,inputObj);
}
}
{
var topPos = vp_Menu_getTopPos(inputObj);
vp_active_Menu = document.getElementById(id);
vp_active_Menu.style.top = topPos + 20 + "px";
vp_active_Menu.style.left = leftPos + "px";
vp_active_Menu.style.zIndex = '50';
vp_active_Menu.style.display = 'block';
vp_active_Menu.style.visibility='visible';
}
el = window.event.srcElement.id;
else
el = event.target.id;
vp_active_Menu.style.visibility = "hidden";
}
{
var returnValue = inputObj.offsetTop;
while((inputObj = inputObj.offsetParent)!= null){
if(inputObj.tagName!='HTML')returnValue += inputObj.offsetTop;
}
return returnValue;
}
{
var returnValue = inputObj.offsetLeft;
while((inputObj = inputObj.offsetParent)!= null){
if(inputObj.tagName!='HTML')returnValue += inputObj.offsetLeft;
}
return returnValue;
}
document.attachEvent("onclick", vp_Menu_Hide);
} else {
document.addEventListener("click", vp_Menu_Hide, false);
}
the problem is on "function vp_Menu_Hide(event) {"
if I click somewhere in page first time and not in link of menu I get an error. on This line:
if (el!= 'vp_menu_container' && vp_active_Menu.style.visibility == 'visible') {
vp_active_Menu.style.visibility = "hidden";
}
How I can solve this? can help any one?
the problem is on "function vp_Menu_Hide(event) {"
if I click somewhere in page first time and not in link of menu I get an error. on This line:if (el!= 'vp_menu_container' && vp_active_Menu.style.visibility == 'visible') {
vp_active_Menu.style.visibility = "hidden";
}How I can solve this? can help any one?
At first glance it appears vp_active_Menu is empty, just add a validation to make sure it exists.
Use this instead of what you currently have:
if(vp_active_Menu){
if (el!= 'vp_menu_container' && vp_active_Menu.style.visibility == 'visible') {
vp_active_Menu.style.visibility = "hidden";
}
}