Hello,
I have created a context menu in mozilla by using following code:
This code is working perfectly.
Now my context menu is closed when i am moving my mouse out from that window. But what i want is i want to close my contextmenu by clicking any where in window not on mouse out of that context menu.
Do anybody has any solution kindly help me.
Do anybody has any other way to create a context menu. If it is help me.
19 3195 gits 5,390
Expert Mod 4TB
hi ...
first replace your line 71 with: - document.onclick = function(event) { closeMenu(event) };
and declare the following method: - function closeMenu(e) {
-
var id = 'contextMenu';
-
-
if (e.target.id != id) {
-
document.getElementById(id).style.visibility = 'hidden';
-
}
-
}
-
this should do the job for mozilla :)
kind regards
hi ...
first replace your line 71 with: - document.onclick = function(event) { closeMenu(event) };
and declare the following method: - function closeMenu(e) {
-
var id = 'contextMenu';
-
-
if (e.target.id != id) {
-
document.getElementById(id).style.visibility = 'hidden';
-
}
-
}
-
this should do the job for mozilla :)
kind regards
Hi gits,
Thanks a lot.
But when i am doing left click in the window that context menu is closed but not by the right click of mouse, as default context menu of each window.
When i am doing right click after getting context menu again one context menu is created. Then if i am doing left click the latest menu is closed and the previous one still opened.
Do you have any solution for that.
gits 5,390
Expert Mod 4TB
nope ... i tested it again in FF 2.0.0.11 ... and when you right-click in the window a new context-menu is created at the mous-pos while the old one is closed ... the right-click is a click too so the click-handler will be called and then the oncontext-menu appears and creates a new one ...
in case you want to ensure that only one contextMenu will be visible then put:
right at the start of your oncontextmenu-handler-function (orig. line 5 of your posted code) ...
kind regards
nope ... i tested it again in FF 2.0.0.11 ... and when you right-click in the window a new context-menu is created at the mous-pos while the old one is closed ... the right-click is a click too so the click-handler will be called and then the oncontext-menu appears and creates a new one ...
in case you want to ensure that only one contextMenu will be visible then put:
right at the start of your oncontextmenu-handler-function (orig. line 5 of your posted code) ...
kind regards
Whatever you have written that is correct. But it is not working. I tried your last solution also.
For each right click i am getting one context menu. Mail me some other way.
gits 5,390
Expert Mod 4TB
nope ... i don't :) ... you should post your code so that i could trace for the error ... as i said the code i used here works for me ... so may be you did something additionally?
nope ... i don't :) ... you should post your code so that i could trace for the error ... as i said the code i used here works for me ... so may be you did something additionally?
My whole code i am sending you.
With the above i am able to close my context menu by left click.
But after getting one context menu if i am doing right click then again one window is coming. Now if you will do left click then the latest window be closed and the first window is still there.
Check my code and tell me what to do.
Hi gits,
I am working in linux platform. Now i came to know When i am running my code in mozilla of linux platform it is not working means (close the context menu right click is not working). But when i tried it in mozilla of XP it is working.
can you please tell me why it is like this and what to do.
gits 5,390
Expert Mod 4TB
hi ...
could you see the alert when you change the line to this: - document.onclick = function(event) {
-
alert('test click');
-
closeMenu(event);
-
};
and do a rightclick in the window?
kind regards
PS: please use code tags when posting source-code
hi ...
could you see the alert when you change the line to this: - document.onclick = function(event) {
-
alert('test click');
-
closeMenu(event);
-
};
and do a rightclick in the window?
kind regards
PS: please use code tags when posting source-code
for only left click i am getting alert message. But when trying to close context menu by using right click i am not getting alert.
And one thing that code is working perfectly, according your last post, in mozilla of XP OS not in linux.
gits 5,390
Expert Mod 4TB
does the linux-moz have any extension installed? i think its a problem with the moz itself not the os? ... i could test it on a mac when i'm at home again :)
kind regards
does the linux-moz have any extension installed? i think its a problem with the moz itself not the os? ... i could test it on a mac when i'm at home again :)
kind regards
I found one extension which is DOM Inspector 1.1.1.8.
I disabled that one still right click is not working.
Is there any way to know extensions and what is the solutions for my problem.
Regards,
Bibhu
gits 5,390
Expert Mod 4TB
hi ...
in your code try to use: - document.oncontextmenu = function (evt) {
-
closeMenu(evt);
-
// your further code here
-
}
-
and put an alert here: - function closeMenu(e) {
-
var id = 'contextMenu';
-
-
alert(e.target.nodeName);
-
-
if (e.target.id != id) {
-
document.getElementById(id).style.visibility = 'hidden';
-
}
-
}
-
post what the alert says :)
kind regards
hi ...
in your code try to use: - document.oncontextmenu = function (evt) {
-
closeMenu(evt);
-
// your further code here
-
}
-
and put an alert here: - function closeMenu(e) {
-
var id = 'contextMenu';
-
-
alert(e.target.nodeName);
-
-
if (e.target.id != id) {
-
document.getElementById(id).style.visibility = 'hidden';
-
}
-
}
-
post what the alert says :)
kind regards
Hi gits,
I am getting "TD" for left click. But for right click i am not getting anything.
Whenever i am doing right click, i think that closeMenu function is not called for which i am not getting any alert message..
gits 5,390
Expert Mod 4TB
in case you get a new contextmenu at the new rightclick position the closeMenu()-method has to be called ... how should the contextmenu be created otherwise? i don't get it ;( ... let me check something and i come back this evening with something new :)
gits 5,390
Expert Mod 4TB
ok ... i checked it again ... we should slightly adapt the closeMenu() method: - function closeMenu(e) {
-
var id = 'contextMenu';
-
-
if (e.target.id != id) {
-
var node = document.getElementById(id);
-
-
if (node != null) {
-
node.style.visibility = 'hidden';
-
}
-
}
-
}
-
this avoids an error in case no node with id is present. now use this: - document.oncontextmenu = function (evt) {
-
closeMenu(evt);
-
// your further code here
-
}
-
i guess it will work now :)
kind regards
ok ... i checked it again ... we should slightly adapt the closeMenu() method: - function closeMenu(e) {
-
var id = 'contextMenu';
-
-
if (e.target.id != id) {
-
var node = document.getElementById(id);
-
-
if (node != null) {
-
node.style.visibility = 'hidden';
-
}
-
}
-
}
-
this avoids an error in case no node with id is present. now use this: - document.oncontextmenu = function (evt) {
-
closeMenu(evt);
-
// your further code here
-
}
-
i guess it will work now :)
kind regards
Hi gits,
I wrote the following code in my closeMenu func, with -
document.onclick=function (evt) {
-
closeMenu(evt);
-
}
-
-
function closeMenu(e) {
-
var id = 'contextMenu';
-
if (e.target.id != id) {
-
var node = document.getElementById(id);
-
if (node != null) {
-
node.style.visibility = 'hidden';
-
}
-
}
-
}
-
only left is working.
But when i wrote like the following: -
document.oncontextmenu=function (evt) {
-
closeMenu(evt);
-
}
-
-
function closeMenu(e) {
-
var id = 'contextMenu';
-
if (e.target.id != id) {
-
var node = document.getElementById(id);
-
if (node != null) {
-
node.style.visibility = 'hidden';
-
}
-
}
-
}
-
neither left click nor right click is working.
Regards,
Bibhu
gits 5,390
Expert Mod 4TB
hi ...
of course you should have added the closeMenu(evt);-call to the top of the oncontextmenu-handler ... not only replace the code :) ... my comment said that your further code should follow there ... the following is how your oncontextmenu-handler should look like: -
document.oncontextmenu = function (evt) {
-
closeMenu(evt);
-
-
var srcElement;
-
-
if (evt && evt.target) {
-
srcElement = evt.target;
-
-
if (srcElement.nodeType == 3) {
-
srcElement = srcElement.parentNode;
-
} else if (window.event) {
-
srcElement = window.event.srcElement;
-
}
-
-
if (srcElement) {
-
if (typeof contextMenu == 'undefined') {
-
contextMenu = createContextMenu('contextMenu');
-
}
-
-
if (contextMenu != null) {
-
var coords = getPageCoords(evt ? evt : window.event);
-
-
contextMenu.style.left = coords.x;
-
contextMenu.style.top = coords.y;
-
contextMenu.srcElement = srcElement;
-
contextMenu.style.visibility = 'visible';
-
-
if (evt && evt.preventDefault) {
-
evt.preventDefault();
-
}
-
-
return false;
-
}
-
}
-
}
-
}
-
... don't forget our latest adaption to the closeMenu()-function ... it worked for me in all test-cases (FF win/mac)
kind regards
hi ...
of course you should have added the closeMenu(evt);-call to the top of the oncontextmenu-handler ... not only replace the code :) ... my comment said that your further code should follow there ... the following is how your oncontextmenu-handler should look like: -
document.oncontextmenu = function (evt) {
-
closeMenu(evt);
-
-
var srcElement;
-
-
if (evt && evt.target) {
-
srcElement = evt.target;
-
-
if (srcElement.nodeType == 3) {
-
srcElement = srcElement.parentNode;
-
} else if (window.event) {
-
srcElement = window.event.srcElement;
-
}
-
-
if (srcElement) {
-
if (typeof contextMenu == 'undefined') {
-
contextMenu = createContextMenu('contextMenu');
-
}
-
-
if (contextMenu != null) {
-
var coords = getPageCoords(evt ? evt : window.event);
-
-
contextMenu.style.left = coords.x;
-
contextMenu.style.top = coords.y;
-
contextMenu.srcElement = srcElement;
-
contextMenu.style.visibility = 'visible';
-
-
if (evt && evt.preventDefault) {
-
evt.preventDefault();
-
}
-
-
return false;
-
}
-
}
-
}
-
}
-
... don't forget our latest adaption to the closeMenu()-function ... it worked for me in all test-cases (FF win/mac)
kind regards
Hi gits,
Thanks a lot. That one is working perfectly.
What i had done that i called that function at last of my context menu handler.
Now it is working perfectly.
But like other default context menu cant it be closed on right click means after getting context menu if i am doing right click new one is generated and the first one is closed.
I am very happy that it is working.
If you any idea for the above case then mail me. But it is very good.
Thanks a lot.
Regards,
Bibhu
gits 5,390
Expert Mod 4TB
hi ...
glad to hear that ... in case you call it first (the closeMenu) then it should work as you intended ... it closes the eventually open contextmenu and creates a new one ...
kind regards
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Shang Wenbin |
last post by:
Hi,
When I want to close the current window using window.close() in IE6.0,
there will be a confirm box that: The web page you are viewing is trying
to close the window. Do you want to close this...
|
by: Chuck Hartman |
last post by:
I have a Windows service that requests web pages from a site using an
HttpWebRequest object. When I try to request a page from an ASP.NET 2 site,
I get a WebException with message "The remote...
|
by: stephen |
last post by:
I have created an order form that users javascript to create a new html
document when the customers clicks the "print page" button.
Once the new document has been created it then prints the...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |