Solved

document.oncontext menu doesn't appear

Posted on 2008-11-01
3
216 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
  • 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

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

Suggested Solutions

Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
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…
How to create a custom search shortcut to site-search Experts Exchange using Google in the Firefox browser. This eliminates the need to type out site:experts-exchange.com whenever you want to search the site. Launch your Bookmark Menu: Press 'Ctrl +…

749 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