Solved

document.oncontext menu doesn't appear

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
#Citrix #Internet Explorer #Enterprise Mode #IE 11 #IE 8
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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.

708 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

20 Experts available now in Live!

Get 1:1 Help Now