/    Sign up×
Community /Pin to ProfileBookmark

Context Menu not on Top

I have an Web page in ASP and Java with a third party object reflected on the page. I have incorporated Javascript Menuing code to try to expose a “Right Mouse Context Menu”
which would be “On Top” of all other items on the web page.

When I execute the rightclick, the menu displays nicely, but it is behind the “third party object”. I have tried “z-index” but it does not seem to resolve the problem with this object. Shrunken example of the page is below. If I change the classid of the object so it is invalid, the context menu shows perfectly, but if the object is valid and displayed, the menu is rendered behind the object. Any ideas would be greatly appreciated. Code follows with reference to the actual third party object. I thnk the same prob would exist with a different third party object.
=====================

<html>
<head>
<style>
<!—
.skin0{
position:absolute;
width:200px;
border:2px solid black;
background-color:menu;
font-family:Verdana;
line-height:20px;
cursor:default;
visibility:hidden;
z-index: 500;
}

.skin1{
cursor: default;
font: menutext;
position: absolute;
width: 165px;
background-color: menu;
border: 1 solid buttonface;
visibility:hidden;
border: 2 outset buttonhighlight;
z-index: 500;
}

.contextmenuitems{
padding-left:15px;
padding-right:10px;
}
–>
</style>

<script language=”JavaScript1.2″>
<!—
//set the skin of the menu (0 or 1, with 1 rendering a default Windows menu like skin)
var menuskin=1

//set this variable to 1 if you wish the URLs of the highlighted menu to be displayed in the status bar
var display_url=0

function showmenuie5(){
//Find out how close the mouse is to the corner of the window
var rightedge=document.body.clientWidth-event.clientX
var bottomedge=document.body.clientHeight-event.clientY

//if the horizontal distance isn’t enough to accomodate the width of the context menu
if (rightedge<ie5menu.offsetWidth){
//move the horizontal position of the menu to the left by it’s width
ie5menu.style.left=document.body.scrollLeft+event.clientX-ie5menu.offsetWidth;
}
else
{
//position the horizontal position of the menu where the mouse was clicked
ie5menu.style.left=document.body.scrollLeft+event.clientX;
}
//same concept with the vertical position
if (bottomedge<ie5menu.offsetHeight){
ie5menu.style.top=document.body.scrollTop+event.clientY-ie5menu.offsetHeight;
}
else
{
ie5menu.style.top=document.body.scrollTop+event.clientY;
ie5menu.style.visibility=”visible”;

//alert(“LEFT ” + ie5menu.style.left);
//alert(“TOP ” + ie5menu.style.top);

}

return false
}

function hidemenuie5(){
ie5menu.style.visibility=”hidden”
}

function highlightie5(){
if (event.srcElement.className==”contextmenuitems”){
event.srcElement.style.backgroundColor=”highlight”
event.srcElement.style.color=”white”
if (display_url==1)
window.status=event.srcElement.url
}
}

function lowlightie5(){
if (event.srcElement.className==”contextmenuitems”){
event.srcElement.style.backgroundColor=””
event.srcElement.style.color=”black”
window.status=”
}
}

function jumptoie5(){
if (event.srcElement.className==”contextmenuitems”){
if (event.srcElement.getAttribute(“target”)!=null)
window.open(event.srcElement.url,event.srcElement.getAttribute(“target”))
else
window.location=event.srcElement.url
}
}

–>
</script>

</head>
<body>

<SCRIPT language=”JavaScript1.2″>
<!—

function CheckButton(){
var s
s=event.button;
if (s==2){
showmenuie5();
}
else
{
hidemenuie5();
}
}

–>
</SCRIPT>

<DIV valign=”top” align=center><span style=”POSITION: relative; TOP: 0px”>
<h3>Test1</h3> </span></DIV>

<div onmousedown=CheckButton() ID=TextEntry STYLE =”Z-INDEX: -500; WIDTH: 600px”>
<OBJECT id=Microsoft_Licensed_Class_Manager_1_0 style=”Z-INDEX: -500″
classid=clsid:5220cb21-c88d-11cf-b347-00aa00a28331 VIEWASTEXT></OBJECT>
<!–TX Text Control –><!–Button Bar–><!–TX Text Control –><!–Text Control–>
<OBJECT id=objTX style=”Z-INDEX: -300; LEFT: 0px; TOP: 0px”
codeBase=Tx.cab#Version=9,0,120,501
classid=clsid:3D6D5D2F-B9F2-101C-AED5-00608CF525A5 width=400 height=250
VIEWASTEXT>
<PARAM NAME=”_Version” VALUE=”65540″>
</OBJECT>
</div></TD></TR></TABLE></SPAN>
<DIV></DIV>

<div id=’ie5menu’ class=’skin0′ onMouseover=’highlightie5()’ onMouseout=’lowlightie5()’ onClick=’jumptoie5()’ >
<div class=’contextmenuitems’ >Copy</div>
<div class=’contextmenuitems’ >Paste</div>
<hr>
<div class=’contextmenuitems’ >Email Me</div>
</div>

<script language=”JavaScript1.2″>
<!—
if (document.all&&window.print){
if (menuskin==0){
ie5menu.className=”skin0″;
}
else
{
ie5menu.className=”skin1″;
}
document.oncontextmenu=showmenuie5;
document.body.onclick=hidemenuie5;
}
–>
</script>
</body>
</html

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@ShrineDesignsDec 15.2002 — when using the z index don't use spaces [b]z-index:2;[/b] also the z-index should be the last item in the style attribute. i don't think there is a z-index of +/- 500; 1 represents the bottom most layer
Copy linkTweet thisAlerts:
@lexusrbauthorDec 16.2002 — Thanks for the advice. I think i followed it religiously,but no change occured. Page still performs as previously described.

New version of code follows, in case I did something silly.

Roger
========================================


<html>

<head>

<style>

<!---

.skin0{

position:absolute;

width:200px;

border:2px solid black;

background-color:menu;

font-family:Verdana;

line-height:20px;

cursor:default;

visibility:hidden;

z-index:3;

}

.skin1{

cursor: default;

font: menutext;

position: absolute;

width: 165px;

background-color: menu;

border: 1 solid buttonface;

visibility:hidden;

border: 2 outset buttonhighlight;

z-index:3;

}

.contextmenuitems{

padding-left:15px;

padding-right:10px;

}

-->

</style>

<script language="JavaScript1.2">

<!---

//set the skin of the menu (0 or 1, with 1 rendering a default Windows menu like skin)

var menuskin=1

//set this variable to 1 if you wish the URLs of the highlighted menu to be displayed in the status bar

var display_url=0


function showmenuie5(){

//Find out how close the mouse is to the corner of the window

var rightedge=document.body.clientWidth-event.clientX

var bottomedge=document.body.clientHeight-event.clientY

//if the horizontal distance isn't enough to accomodate the width of the context menu

if (rightedge<ie5menu.offsetWidth){

//move the horizontal position of the menu to the left by it's width

ie5menu.style.left=document.body.scrollLeft+event.clientX-ie5menu.offsetWidth;

}

else

{

//position the horizontal position of the menu where the mouse was clicked

ie5menu.style.left=document.body.scrollLeft+event.clientX;

}

//same concept with the vertical position

if (bottomedge<ie5menu.offsetHeight){

ie5menu.style.top=document.body.scrollTop+event.clientY-ie5menu.offsetHeight;

}

else

{

ie5menu.style.top=document.body.scrollTop+event.clientY;

ie5menu.style.visibility="visible";

//alert("LEFT " + ie5menu.style.left);

//alert("TOP " + ie5menu.style.top);

}

return false

}

function hidemenuie5(){

ie5menu.style.visibility="hidden"

}

function highlightie5(){

if (event.srcElement.className=="contextmenuitems"){

event.srcElement.style.backgroundColor="highlight"

event.srcElement.style.color="white"

if (display_url==1)

window.status=event.srcElement.url

}

}

function lowlightie5(){

if (event.srcElement.className=="contextmenuitems"){

event.srcElement.style.backgroundColor=""

event.srcElement.style.color="black"

window.status=''

}

}

function jumptoie5(){

if (event.srcElement.className=="contextmenuitems"){

if (event.srcElement.getAttribute("target")!=null)

window.open(event.srcElement.url,event.srcElement.getAttribute("target"))

else

window.location=event.srcElement.url

}

}

-->

</script>

</head>

<body>



<SCRIPT language="JavaScript1.2">

<!---

function CheckButton(){

var s

s=event.button;

if (s==2){

showmenuie5();

}

else

{

hidemenuie5();

}

}

-->

</SCRIPT>

<br>

<br>

<br>

<br>

<div onmousedown=CheckButton() ID=TextEntry STYLE ="Z-INDEX:1">

<OBJECT id=Microsoft_Licensed_Class_Manager_1_0

classid=clsid:5220cb21-c88d-11cf-b347-00aa00a28331 VIEWASTEXT>

</OBJECT>

<!--TX Text Control --><!--Text Control-->

<OBJECT id=objTX codeBase=Tx.cab#Version=9,0,120,501

classid=clsid:3D6D5D2F-B9F2-101C-AED5-00608CF525A5 width=400 height=250

VIEWASTEXT style="LEFT:0px; TOP:0px; z-index:1">

<PARAM NAME="_Version" VALUE="65540">

</OBJECT>

</div>

<div id='ie5menu' class='skin0' onMouseover='highlightie5()' onMouseout='lowlightie5()' onClick='jumptoie5()' >

<div class='contextmenuitems' >Copy</div>

<div class='contextmenuitems' >Paste</div>

<hr>

<div class='contextmenuitems' >Email Me</div>

</div>

<script language="JavaScript1.2">

<!---

if (document.all&&window.print){

if (menuskin==0){

ie5menu.className="skin0";

}

else

{

ie5menu.className="skin1";

}

document.oncontextmenu=showmenuie5;

document.body.onclick=hidemenuie5;

}

-->

</script>

</body>

</html>
Copy linkTweet thisAlerts:
@ShrineDesignsDec 16.2002 — it's working perfect on my system
Copy linkTweet thisAlerts:
@ShrineDesignsDec 16.2002 — and it works fine on my site too

i changed a couple of thing

<html>

<head>

<style type="text/css">

<!--

.skin0 {

position: absolute;

width: 200px;

border: 2px solid black;

background-color: menu;

font-family: Verdana;

line-height: 20px;

cursor: default;

visibility: hidden;

z-index:3;

}

.skin1 {

cursor: default;

font: menutext;

position: absolute;

width: 165px;

background-color: menu;

border: 1px solid buttonface;

visibility: hidden;

border: 2px outset buttonhighlight;

z-index:3;

}

.contextmenuitems {

padding-left: 15px;

padding-right: 10px;

}

-->

</style>

<script language="JavaScript1.2">

<!--

//set the skin of the menu (0 or 1, with 1 rendering a default Windows menu like skin)

var menuskin = 1;

//set this variable to 1 if you wish the URLs of the highlighted menu to be displayed in the status bar

var display_url = 0;

function showmenuie5(){

//Find out how close the mouse is to the corner of the window

var rightedge = document.body.clientWidth - event.clientX;

var bottomedge = document.body.clientHeight - event.clientY;

//if the horizontal distance isn't enough to accomodate the width of the context menu

if (rightedge < ie5menu.offsetWidth){

//move the horizontal position of the menu to the left by it's width

document.ie5menu.style.left = document.body.scrollLeft + event.clientX - ie5menu.offsetWidth;

}

else {

//position the horizontal position of the menu where the mouse was clicked

ie5menu.style.left = document.body.scrollLeft + event.clientX;

}

//same concept with the vertical position

if (bottomedge < ie5menu.offsetHeight){

ie5menu.style.top = document.body.scrollTop + event.clientY - ie5menu.offsetHeight;

}

else {

ie5menu.style.top = document.body.scrollTop + event.clientY;

ie5menu.style.visibility = "visible";

//alert("LEFT " + ie5menu.style.left);

//alert("TOP " + ie5menu.style.top);

}

return false;

}

function hidemenuie5(){

ie5menu.style.visibility = "hidden";

}

function highlightie5(){

if (event.srcElement.className == "contextmenuitems"){

event.srcElement.style.backgroundColor = "highlight";

event.srcElement.style.color = "white";

if (display_url == 1)

window.status = event.srcElement.url;

}

}

function lowlightie5(){

if (event.srcElement.className == "contextmenuitems"){

event.srcElement.style.backgroundColor = "";

event.srcElement.style.color = "black";

window.status = '';

}

}

function jumptoie5(){

if (event.srcElement.className == "contextmenuitems"){

if (event.srcElement.getAttribute("target") != null)

window.open(event.srcElement.url,event.srcElement.getAttribute("target"));

else

window.location = event.srcElement.url;

}

}

//-->

</script>

</head>

<body>

<SCRIPT language="JavaScript1.2">

<!--

function CheckButton(){

var s = event.button;

if (s == 2){

showmenuie5();

}

else {

hidemenuie5();

}

}

//-->

</SCRIPT>

<br>

<br>

<br>

<br>

<div id="TextEntry" style="z-index:1;" onmousedown="CheckButton()">

<OBJECT id="Microsoft_Licensed_Class_Manager_1_0" classid="clsid:5220cb21-c88d-11cf-b347-00aa00a28331" VIEWASTEXT>

</OBJECT>

<!--TX Text Control -->

<!--Text Control-->

<OBJECT id="objTX" codeBase="Tx.cab#Version=9,0,120,501" classid="clsid:3D6D5D2F-B9F2-101C-AED5-00608CF525A5" width="400" height="250" style="top:0px; left:0px; z-index:1;" VIEWASTEXT>

<PARAM NAME="_Version" VALUE="65540">

</OBJECT>

</div>

<div id="ie5menu" class="skin0" onMouseover="highlightie5()" onMouseout="lowlightie5()" onClick="jumptoie5()">

<div class="contextmenuitems">Copy</div>

<div class="contextmenuitems">Paste</div>

<hr>

<div class="contextmenuitems">Email Me</div>

</div>

<script language="JavaScript1.2">

<!--

if (document.all && window.print){

if (menuskin == 0){

ie5menu.className = "skin0";

}

else {

ie5menu.className = "skin1";

}

document.oncontextmenu = showmenuie5;

document.body.onclick = hidemenuie5;

}

//-->

</script>

</body>

</html>
Copy linkTweet thisAlerts:
@lexusrbauthorDec 16.2002 — wow, I am stumped. I copied your version into a .htm and ran it on two different machines. one ie5.5, the other ie6.

In both case, when i right moused just above the object, the context menu only partially shows and the rest of the menu is hidden behind the object. I am going to try it again tomorrow at another site with another machine, but something else is going on here?:mad:

Thanks for all the thoughts and efforts.

BTW. What object did you substitute for the TXText object?

I don't suppose you had access to that object.
Copy linkTweet thisAlerts:
@ShrineDesignsDec 16.2002 — i use the as i had posted

the object was blank

give this a try

<div id="ie5menu" onMouseover="highlightie5()" onMouseout="lowlightie5()" onClick="jumptoie5()" style="position: absolute; width: 200px; border: 2px solid black; background-color: menu; font-family: Verdana; line-height: 20px; cursor: default; visibility: hidden; z-index:3;">

<div class="contextmenuitems">Copy</div>

<div class="contextmenuitems">Paste</div>

<hr>

<div class="contextmenuitems">Email Me</div>

</div>

before i did this the font was not Verdana and the border was not 2px solid black
Copy linkTweet thisAlerts:
@lexusrbauthorDec 16.2002 — aha!. The reason you saw the menu in your previous example is that the "object" was probably not rendered (ie: you saw a white box and you don't have the class id on your machine ). If I make the object invalid on my machine (by changing the class id by one digit), i also get a white box and I get the entire menu. But if you had a valid "object", my guess is it would not show thru. ?
×

Success!

Help @lexusrb spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...