Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

calling contextmenu

Status
Not open for further replies.

mountainbiker

Programmer
Aug 21, 2002
122
GB
if i trap the contextmenu event in ie with

document.oncontextmenu=alert("called content menu")

how can i get the context menu to fire after the alert?
 
<SCRIPT LANGUAGE=javascript>
document.oncontextmenu=docontextmenu;
function docontextmenu(){
alert("called content menu");
return true;
}
</SCRIPT>

Adam
while(ignorance){perpetuate(violence,fear,hatred);life=life-1};
 
in ie5.5 + 6, i have been finding if you interrupt the event with an alert it won't fire the event after the interruption.

here is some code i was working with last night. i got a solution going at work today. unfortunately, don't have this code polished up to show here. however, this code gives a good idea of the final solution.

Code:
		<script language="JavaScript">
		<!--
		overImage=0;
		title='NOT SET';
		msg="NOT SET";

		// Event handler		
		function mouseDown(e) {
			if (!e) var e=window.event;

			var clickType=1;
			var tgt="";
		
			if (parseInt(navigator.appVersion)>3) {
				if (navigator.appName=="Netscape") {
					clickType=e.which;
					tgt=""+e.target;
					if (tgt.length!=0 && tgt.charAt(tgt.length-1)=="#") {
//					if (tgt.length!=0 && TARGET_IS_AN_IMAGE) {
//						alert('tgt='+tgt);
						overImage=1;
					}
					else {
//						alert('tgt='+e.type+' '+e.which);
					}				
				} else {
					clickType=e.button;
//					alert("event type="+e.type+"\nClicktype="+clickType+"\n"+e.srcElement.id+"\n"+e.srcElement.src+"\n"+e.srcElement.tagName);
					if (""+e.srcElement.className=="disabledMenu") {
						overImage=1;
					}
				}
				
				if (clickType!=1 && overImage) {
					msg = 'If you save this image locally, the title';
					msg += 'will not be a part of the image.\n'+title;
					if (navigator.appName=="Netscape") { alert ("mouseDown: "+msg); }
					return true;   // netscape: true = show context menu; false = don't show
				}
			}

			return true;
		}
		
		function mouseUp(e) {
			if (!e) var e=window.event;

			var clickType=1;
			var tgt="";
		
			if (parseInt(navigator.appVersion)>3) {
				if (navigator.appName=="Netscape") {
					clickType=e.which;
					tgt=""+e.target;
					if (tgt.length!=0 && tgt.charAt(tgt.length-1)=="#") {
//						alert('tgt='+tgt);
						overImage=1;
					}
					else {
//						alert('tgt='+e.type+' '+e.which);
					}				
				} else {
					clickType=e.button;
//					alert("event type="+e.type+"\nClicktype="+clickType+"\n"+e.srcElement.id+"\n"+e.srcElement.src+"\n"+e.srcElement.tagName);
					if (""+e.srcElement.className=="disabledMenu") {
						overImage=1;
					}
				}
				
				if (clickType!=1 && overImage) {
					msg = 'If you save this image locally, the title ';
					msg += 'will not be a part of the image.\n'+title;
					if (navigator.appName!="Netscape") { alert ("mouseUP: "+msg); }
					return true;   // netscape: true = show context menu; false = don't show
				}
			}

			return true;
		}

		//-------------------------------
		// Capture all mouseDown events
		// 	and send 'em to informUser()
		//-------------------------------
		if (parseInt(navigator.appVersion)>3) {
			document.onmousedown = mouseDown;			
			if (navigator.appName=="Netscape") {
				document.captureEvents(Event.MOUSEDOWN);
			} else {
				document.onmouseup = mouseUp;
			}
		}
		//-->
		</script>



      	<h1>1 for ie</h1>
      	<!--
			<a href="#"
				id="HREFID"
				onClick="return false" 
				onMouseOver="overImage=1;hidestatus();title='test title';return false"><img
				onmouseup="overImage=0;return false;"
					id="IMGID"
					border="0" 
					src="JACWORld2.GIF" 
					class="disabledMenu"></a>
					-->
			<img id="IMGID"
				onClick="return false" 
				onMouseOver="overImage=1;title='test title';return false"
				onmouseup="overImage=0;return false;"
					id="IMGID"
					border="0" 
					src="WORLD.GIF" 
					class="disabledMenu">     
			<hr />

      	<h1>1 for netscape</h1>
      	<!-- 
      	need to wrap netscape in href so we can look for the # in target 
      	otherwise maybe we can just check if it is an .jpg, .png, etc. and have
      	href="." 
      	-->
			<a href="#"
				id="HREFID"
				onClick="return false" 
				onMouseOver="overImage=1;hidestatus();title='test title';return false"
				onMouseOut="overImage=0;return false"><img
					id="IMGID"
					border="0" 
					src="WORLD.GIF" 
					class="disabledMenu"></a>
     
			<hr />
 
Hmm, I'm using IE6.0 and the code I posted earlier works fine for me. mountainbiker, does my code not work for you?

Adam
while(ignorance){perpetuate(violence,fear,hatred);life=life-1};
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top