Forum Moderators: open

Message Too Old, No Replies

Two Qs concerning right click customizing

(1) block context menu (2) link click after click event

         

Stue

10:57 am on Jun 6, 2002 (gmt 0)

10+ Year Member



Hi,

im currently building a custom context-menu that should be working in IE4+ and NS4+.

Question 1: How do i prevent the context-menu from popping up in IE4+ ?

I am assigning a function to the document.onmouseup event (because the normal context menu also pops up on mouseup). This function makes a div layer visible, which contains several image links, if the mouse button is the right one. The bugging part of it is, that the normal context menu ALSO pops up, after the layer has been made visible. So it basically overlayers the custom one.
But i want to prevent this. In NS4 you can simply return a false after the function and the normal context menu wont popup. In IE however this wont work.

Fortunately, the IE6 (and probably IE5 too) has a seperate event handler called obcontextmenu which makes the whole deal more that easy.

So, if anyone thinks s/he has a solution to this, please post.

Question 2: How to prevent the onclick event to fire before the link-click ?

I have assigned a function to the onmouseup event which, if the LEFT button is hit, will hide the custom context menu layer again. The problem is, that i have links in my context menu. So if I click on a link i will want the function assigned to the link to fire AND the global onmouseup event, too..to hide the menu, of course.

IE seems to do this correct. First firing the link click, then firing the global onmouseup event. NS4 however ignores the link click and only fires the onmouseup event. So my links become useless.

So i might try to DISABLE the global onmouseup event when i click a link (and integrate the hiding function into the link function itself). But how would i do this?
If i click on the document or anywhere else than a link on my custom context menu, i want the menu to hide.
But if i click on a link on my custom context menu i want the link function to fire.

I hope people here have experience with workarounds like this. Thanks in advance for any posts.

Stue

11:37 am on Jun 6, 2002 (gmt 0)

10+ Year Member



OK i found a workaround for Question 2.
Here it goes:

In the function that is fired by the global onmouseup event, check the target of the event. If the target is a link, simply execute the link.

Lets say we have a link
<A href="javascript:doFunction();">
then the following code is added to the mouseup function:

target = ""+ e.target; //make it a string
target.match(/javascript:(.*?)/); //parse the actual function name out of it
eval(RegExp.$1); //evaluate/execute the function

Stue

11:25 am on Jun 7, 2002 (gmt 0)

10+ Year Member



Id like to add two new thought to this issue...as this is still not over for me!

(1)

window.event.cancelBubble = true;
will prevent an event to "bubble up" the way thru the parents to the document on the search for an element to HANDLE the event

window.event.returnValue = false;
will cancel the default action assigned to the element

In my endless neverending search for a solution i digged up this thread:
[freewarejava.com...]

But the only useful thing in the script there is the oncontextmenu handling. The use of cancelBubble and returnValue seem to have no effect and thus are redundant!

Anyway, just a thought here. Maybe one of you knows how to use these correctly.

(2)

Another thought was to replace the alert() dummy command everybody uses for preventing the context menu from popping up by "(message)"; before the return false; where message has been set to "" before.

I found this idea here:
[dynamicdrive.com...]

It sais its for All browsers including IE4. But once again it doesnt work at all.

Just another thought added to this topic.

Come on guys. Dont let me do monologues here.

Lorel

1:31 am on Jun 8, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hi Stue,

"It sais its for All browsers including IE4. But once again it doesnt work at all."

How about those of us that don't have two buttons on our mouse :)

txbakers

1:38 am on Jun 8, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Please don't mess with the right clicking on the window.

It only serves to annoy the users. If you are trying to avoid people seeing your code or stealing images, forget about it.

papabaer

2:16 am on Jun 8, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello Stue,

Sounds like an interesting project, but I wonder if you might end up excluding more people than you may believe. Have you give useability real consideration?

Non-typical menu options (right-click or otherwise) are not very intuitive, plus you need to consider the 11-12% of the web-surfing public that surfs with javascript disabled. And as Lorel so aptly pointed out... what about users with a single mouse button?

You always have to ask yourself if the implementation of a "custom" interface will provide a good ROI (return on investment), in terms of user satisfaction, weight of script/coding invloved and increased search engine optimization. Ideally, you want a BIG increase on the first, a marked decrease on the second and an overall improvement on the third.

Without a doubt, the trend is towards simpler interfaces that provide maximum levels of useability. If you are coding for an Intranet then custom interfaces will have a captive audience that will eventually discover all of the custom UI implementations. The Internet is a much different story however: if surfers find themselves confused with a navigation scheme or UI, they use the one they ARE familiar with: the back-button!

fathom

2:27 am on Jun 8, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You also limit them from quick "printing", quick "add to favourite", quick "shortcut", refresh, all google bar options, and that all important property click to see any certificates.

If menu bars are hidden or deselect to increase screen viewing area you have pretty much given your visitors to your competition.

Might want to re-think your strategy. Personally I don't trust companies that show they don't trust anyone... especially their visitors!

joshie76

5:54 pm on Jun 9, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Stue,

Question 1: How do i prevent the context-menu from popping up in IE4+ ?

I've had this same problem awhile ago and posted about it (can't find it though).

From memory my findings where that there is no *real* way of disabling the context menu in all versions of IE without using the oncontextmenu event.

The only *unreal* way to do it is to launch an OS dialog box (i.e. a window.alert, prompt or confirm). As you can see, a total hack, but for some reason it seems to stop the context menu appearing.

Since you want to show a custom menu this would probably get in the way. I never found a better solution but the project I was working on was a corporate app where everybody had IE5+ which supports the oncontextmenu event.

Best o' luck. Let us know if you crack it.

Josh