PDA

View Full Version : [DHTML] Javascript Mouse Object



shachi
02-03-2007, 09:15 AM
1) CODE TITLE: Javascript Mouse Object

2) AUTHOR NAME: Shachi Bista

3) DESCRIPTION: Emulates the A(ction)S(cript) Mouse object(except some features)

4) CODE SIZE: 1187 bytes(without images and markup, not zipped)

5) NOTES: Not sure what the Mouse.hide() and Mouse.show() functions will be useful for.

6) DEMO: http://shachi.eparliament.org/Mouse.html

boxxertrumps
02-03-2007, 05:58 PM
All thats Left is A Tiny Black Dot And You Cant Right Click,

Very nice.

jscheuer1
02-03-2007, 06:20 PM
Doesn't do anything in Opera. In FF the context menu is still available no matter what and I do see the mouse as a dot.

mburt
02-03-2007, 07:10 PM
Only noticed one thing: Hidden w/o context menu causes the mouse to flicker. Good job though

shachi
02-03-2007, 07:59 PM
boxxertrumps: there is an option so that you can right click.

jscheuer1: sorry, haven't tested yet in Opera nor in IE.

mburt, jscheuer1: I can't see any dots or flickers in FF(Iceweasel) 2.0.0.1 and the context menu works just fine. Do you have any clue why these problems are occurring(because I have none)?

Thank you all.

mburt
02-03-2007, 08:20 PM
Well, I'm using FF 1.5.0.9, and the errors I posted occurred.

jscheuer1
02-03-2007, 08:58 PM
FF has a setting that doesn't allow javascript to disable the context menu. I think it is on by default in the FF 1.0.1+ through 1.5.0+ versions. Many NS versions have the same. I don't think Opera allows it to be disabled via javascript, period. You really should test your script in more than one or two browsers before posting it here. A script that hasn't been tested should be presented first in the javascript help section, where you would ask others to test it if you haven't the facilities to do so yourself.

shachi
02-04-2007, 05:48 PM
FF has a setting that doesn't allow javascript to disable the context menu. I think it is on by default in the FF 1.0.1+ through 1.5.0+ versions.

Are you sure about that? I am just asking because earlier I used to use FF v 1.5.0.5 and I could block the context menu with document.oncontextmenu = function(){return false;} without me playing with any of it's preferences.


You really should test your script in more than one or two browsers before posting it here. A script that hasn't been tested should be presented first in the javascript help section, where you would ask others to test it if you haven't the facilities to do so yourself.

I guess I'll have to do the same. Thanks for the suggestion.

Well anyways, did anyone find an effective use for the Mouse.(hide|show) function(s)?

boxxertrumps
02-04-2007, 06:12 PM
so thats what a context menu is...

shachi
02-04-2007, 06:14 PM
boxxertrumps: context menu is the thing that pops up when you right click. Just in case you were confused.

jscheuer1
02-04-2007, 06:27 PM
Are you sure about that? I am just asking because earlier I used to use FF v 1.5.0.5 and I could block the context menu with document.oncontextmenu = function(){return false;} without me playing with any of it's preferences.

If you had changed that setting in any earlier version that you were upgrading from, the change would have been inherited.

I'm sure about NS 7 and FF 1.0.1 (not precisely sure if I have the right numbering convention, what I mean is FF as it first branched off from NS) -any browsers that came later in either of those series would have used the defaults I had previously set as, they were all upgrades. That takes us all the way up to FF 1.5.0.9.

In any case, javascripting of the context menu is easily disabled in most non-IE browsers and default in many. I think, though it is tricky, that fooling with the context menu with javascript can be disabled in IE as well.

shachi
02-04-2007, 06:32 PM
I guess I need to update the context menu code then.

jscheuer1
02-04-2007, 07:08 PM
You know, I would say that it really isn't something I would pursue. I remember at one point I felt a little differently and even posted upgrades to some of the no-right click scripts here at DD. There were ways of getting around restrictions but, the one in FF required that an alert be fired. Add to that the fact that the measures browsers take to prevent javascript from messing with user options is evolving. And, none of this prevents users from copying content. Even with Flash, there are Flash grabbing applications.

If folks want the kind of interface that Flash provides, they should use Flash. If, on the other hand, they are just after some of the functionality or special effects and do not wish to require Flash or to take up the bandwidth then, javascript can often fill that need handily.

If it isn't a matter of preventing copying, the best way that a javascript developer can prevent the context menu from getting in the way of his or her script is to not employ right click for anything. That way the user can use it as they see fit. Most folks know that normal viewing of a web page does not involve right clicking on anything.

shachi
02-04-2007, 07:17 PM
I just need the no-right click to prevent the mouse being shown when the right click is triggered. Nothing else than that. And I made this as Mouse.hide is only available in actionscript and flash isn't available in every browser(but javascript is in most of the browsers).

jscheuer1
02-04-2007, 07:30 PM
If you just want to hide the cursor, use a transparent custom cursor but, it would be better if you could settle on a different trigger than the right click. I've used onmouseover to get a cleaner look to one of those tooltip scripts that has its own arrow. It would depend upon just whatever your needs actually are.

And, though I think you already do, feel free to work it out however you like. All I meant was to be aware that if you choose to co-opt right click for anything, it will not be as widely implemented on the client side as other triggers. This is unavoidable in javascript because there is a natural and evolving antagonism on the part of browsers to keep it that way no matter how you write the code.