...

View Full Version : Right-click menu script problem



Bobo
06-18-2004, 07:12 PM
I have a script for a "right-click" pop-up menu. Unfortunately, there is a problem w/ the script and I cannot determine what it is. Any help is appreciated. The div used for the menu is under the ID "JI" and the code is as follows:

<script language="JavaScript">
<!--hide
var E=window.document.getElementById("JI").style;
function Z(evt) {
if (event.button==2||evt.button==2||event.button==3||evt.button==3) {
var xpos= (evt||event).clientX;
var ypos= (evt||event).clientY;
E.visibility='visible';
E.top=ypos;
E.left=xpos
}
//|3
else if ( ( (evt.clientY>=parseFloat(E.top)&&evt.clientY<=Number(parseFloat(E.top))+parseFloat(E.height)) || (event.clientY>=parseFloat(E.top)&&event.clientY<=Number(parseFloat(E.top))+parseFloat(E.height)) ) && ( (evt.clientX>=parseFloat(E.left)&&evt.clientX<=Number(parseFloat(E.left))+parseFloat(E.width)) || (event.clientX>=parseFloat(E.left)&&event.clientX<=Number(parseFloat(E.left))+parseFloat(E.width)) ) ) {
E.visibilty='visible'
}
else {E.visibility='hidden'}
}
document.onmousedown=Z
//--->
</script>upi

SlySecretSpy
06-18-2004, 10:20 PM
The problem here is that if your running this before the page loads, then the div element "JI" will not exist yet. So you need to place the code...
var E=window.document.getElementById("JI").style;
....inside the function. Like Below.



<script language="JavaScript">
<!--hide
function Z(evt) {
var E=window.document.getElementById("JI").style;
if (event.button==2||evt.button==2||event.button==3||evt.button==3) {
var xpos= (evt||event).clientX;
var ypos= (evt||event).clientY;
E.visibility='visible';
E.top=ypos;
E.left=xpos
}
//|3
else if ( ( (evt.clientY>=parseFloat(E.top)&&evt.clientY<=Number(parseFloat(E.top))+parseFloat(E.height)) || (event.clientY>=parseFloat(E.top)&&event.clientY<=Number(parseFloat(E.top))+parseFloat(E.height)) ) && ( (evt.clientX>=parseFloat(E.left)&&evt.clientX<=Number(parseFloat(E.left))+parseFloat(E.width)) || (event.clientX>=parseFloat(E.left)&&event.clientX<=Number(parseFloat(E.left))+parseFloat(E.width)) ) ) {
E.visibilty='visible'
}
else {E.visibility='hidden'}
}
document.onmousedown=Z
//--->
</script>

Bobo
06-18-2004, 10:40 PM
Cool, that worked out. Apparently there is another problem: when I click on or off the menu to use it or to get rid of it, I get an error saying "button" is null or not an object. I can't seem to fix that either. Any ideas?

SlySecretSpy
06-18-2004, 10:54 PM
I need to see the html that goes with it to see what your passing.

Bobo
06-18-2004, 11:12 PM
This is it minus the stuff not related to the menu.


<html><head><title>Playroom!!</title>
<script language="JavaScript">
<!--hide
function Z(evt) {
var E=window.document.getElementById("JI").style;
if (event.button==2||evt.button==2||event.button==3||evt.button==3) {
var xpos= (evt||event).clientX;
var ypos= (evt||event).clientY;
E.visibility='visible';
E.top=ypos;
E.left=xpos
}
//|3
else if ( ( (evt.clientY>=parseFloat(E.top)&&evt.clientY<=Number(parseFloat(E.top))+parseFloat(E.height)) || (event.clientY>=parseFloat(E.top)&&event.clientY<=Number(parseFloat(E.top))+parseFloat(E.height)) ) && ( (evt.clientX>=parseFloat(E.left)&&evt.clientX<=Number(parseFloat(E.left))+parseFloat(E.width)) || (event.clientX>=parseFloat(E.left)&&event.clientX<=Number(parseFloat(E.left))+parseFloat(E.width)) ) ) {
E.visibilty='visible'
}
else {E.visibility='hidden'}
}
document.onmousedown=Z
//--->
</script>


</head><body bgcolor=steelblue>
<div id="JI" style="left:1;top:1;z-index:279.0879439;visibility:hidden;width:79px;height:379px;position:absolute;border:2.5 tan outset;filter:progID:DXImageTransform.Microsoft.gradient(gradienttype=0,startcolorstr=#0012dc,endcol orstr=royalblue)">![ThisPart is being worked on]</div>






</body></html>

I think the button thing is from ~.button==2/3, however I don't know why it thinks it's 'null or not an object.'

SlySecretSpy
06-18-2004, 11:41 PM
Will this work. You might want to add at least a border to the menu, cause of course that filter won't work in Mozilla.


<html><head><title>Playroom!!</title>
<script language="JavaScript">
<!--hide
function Z(evt) {
var E=window.document.getElementById("JI").style;
var rightclick;
if (!evt) evt = window.event;
if (evt.which) rightclick = (evt.which == 3);
else if (evt.button) rightclick = (evt.button == 2);
if (rightclick != false) {
document.oncontextmenu=new Function("return false") ;
var xpos= evt.clientX;
var ypos= evt.clientY;
E.visibility='visible';
E.top=ypos;
E.left=xpos
}
//|3
else if ( ( (evt.clientY>=parseFloat(E.top)&&evt.clientY<=Number(parseFloat(E.top))+parseFloat(E.height)) || (event.clientY>=parseFloat(E.top)&&event.clientY<=Number(parseFloat(E.top))+parseFloat(E.height)) ) && ( (evt.clientX>=parseFloat(E.left)&&evt.clientX<=Number(parseFloat(E.left))+parseFloat(E.width)) || (event.clientX>=parseFloat(E.left)&&event.clientX<=Number(parseFloat(E.left))+parseFloat(E.width)) ) ) {
E.visibilty='visible'
}
else {E.visibility='hidden'}
}
document.onmousedown=Z;
//--->
</script>
</head><body bgcolor=steelblue>
<div id="JI" style="left:1;top:1;z-index:279.0879439;visibility:hidden;width:79px;height:379px; position:absolute;border:2.5 tan outset;filter:progID:DXImageTransform.Microsoft.gradient(gradienttype=0,startcolorstr=#0012dc,endc olorstr=royalblue)">![ThisPart is being worked on]</div>
</body></html>

Bobo
06-19-2004, 12:57 AM
:thumbsup: That worked perfectly!! THANKS!!!!!!!! BTW, it does have a border. Thanks again!!

SlySecretSpy
06-19-2004, 01:03 AM
border:2.5 tan outset

should be

border:2.5px outset tan



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum