?
Solved

document.oncontext menu doesn't appear

Posted on 2008-11-01
3
Medium Priority
?
223 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 750 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 750 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
This Micro Tutorial will demonstrate how to add subdomains to your content reports. This can be very importing in having a site with multiple subdomains.
Suggested Courses

765 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