Solved

document.oncontext menu doesn't appear

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…
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 +…

863 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now