Solved

document.oncontext menu doesn't appear

Posted on 2008-11-01
3
219 Views
Last Modified: 2013-12-08
Hi to all,
i want to show a context menu on body element. But i don't want any element in body element.
I've coded it but context menu event doesn't fired.
I attached my code. But as i say i don't want any element in <body></body> tag like div table etc...
if i add it so the event raise already.
i use internet explorer 7... ff or others not important for me for this subject..

<body>
</body>
<script language="javascript">
document.body.oncontextmenu=function (){alert("test")};
</script>

Open in new window

0
Comment
Question by:erenpasa
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 35

Accepted Solution

by:
torimar earned 250 total points
ID: 22857474
It works when you put the script code inside the body tags.

Script code isn't an "object" after all, or is it?
<body>
<script language="javascript">
document.body.oncontextmenu=function (){alert("test")};
</script>
</body>

Open in new window

0
 

Assisted Solution

by:Strecher
Strecher earned 250 total points
ID: 22857513
torimar:
Your example doesn't seem to work for me.

Below code worked in FF and IE. Not sure about Opera as it has right click override disabled.
<script language="javascript">
document.oncontextmenu=new Function("alert('test'); return false");
</script>

Open in new window

0
 
LVL 35

Expert Comment

by:torimar
ID: 22857947
I tested within Homesite+ which uses the IE dlls for preview.

However, since I never use IE for browsing, only the default IE 6 is installed. Sorry, didn't realize it explicitly had to work in IE 7.
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
This article discusses how to implement server side field validation and display customized error messages to the client.
Google currently has a new report that is in beta and coming soon to Webmaster Tool accounts. This Micro Tutorial will highlight new features for Google Webmaster Tools.
Shows how to create a shortcut to site-search Experts Exchange using Google in the Chrome browser. This eliminates the need to type out site:experts-exchange.com whenever you want to search the site. Launch the Search Engine Menu: In chrome, via you…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question