Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    Jan 2004
    Location
    Port Huron, MI, U.S.A.
    Posts
    280
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Right-click menu script problem

    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:
    Code:
    <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
    Oh, was I supposed to put something here? ........

  • #2
    New Coder
    Join Date
    Nov 2003
    Posts
    65
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.


    Code:
    <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>

  • #3
    Regular Coder
    Join Date
    Jan 2004
    Location
    Port Huron, MI, U.S.A.
    Posts
    280
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?
    Oh, was I supposed to put something here? ........

  • #4
    New Coder
    Join Date
    Nov 2003
    Posts
    65
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I need to see the html that goes with it to see what your passing.

  • #5
    Regular Coder
    Join Date
    Jan 2004
    Location
    Port Huron, MI, U.S.A.
    Posts
    280
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This is it minus the stuff not related to the menu.

    Code:
    <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,endcolorstr=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.'
    Oh, was I supposed to put something here? ........

  • #6
    New Coder
    Join Date
    Nov 2003
    Posts
    65
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

    Code:
    <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>

  • #7
    Regular Coder
    Join Date
    Jan 2004
    Location
    Port Huron, MI, U.S.A.
    Posts
    280
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up :-)

    That worked perfectly!! THANKS!!!!!!!! BTW, it does have a border. Thanks again!!
    Oh, was I supposed to put something here? ........

  • #8
    New Coder
    Join Date
    Nov 2003
    Posts
    65
    Thanks
    0
    Thanked 0 Times in 0 Posts
    border:2.5 tan outset

    should be

    border:2.5px outset tan


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •