Prevent Selection of Image

270 views
Skip to first unread message

Erik M.

unread,
Jun 4, 2010, 4:51:25 AM6/4/10
to Google Web Toolkit
Hi,

I've got several Image Widgets on my Site. Is there a way to prevent
the selection with the mouse? Selection of an image means its getting
a blue background and being draggable to other windows.
Can you think of an HTML or GWT solution?

I read that one option was to add an mouseMove event handler and let
it "return false;". This was a pure JavaScript solution, not related
to GWT.

Sincerely,
Erik

fmod

unread,
Jun 4, 2010, 2:33:59 PM6/4/10
to Google Web Toolkit
Hi

Use <div style='background: url("image.png");"> GWT can help you
writing this code. http://code.google.com/webtoolkit/doc/latest/DevGuideClientBundle.html#Image_Sprites

Other option is to try to prevent the browser for taking the default
action. (I did not try myself)

image.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
event.preventDefault();
}
});

Regards
-Fran

mP

unread,
Jun 6, 2010, 7:41:37 AM6/6/10
to Google Web Toolkit
Some browsers support a css property that literally prevents the
applied elements from being selected. If i recall one must add
javascript for a particular selection event and cancel for IE and
opera but Safari and FF are easy with a css property being enough.

Erik M.

unread,
Jun 7, 2010, 12:10:11 PM6/7/10
to Google Web Toolkit
Thanks foir your ideas, I'll give them a try tonight!

On Jun 4, 8:33 pm, fmod <francisco.mode...@gdsoft.eu> wrote:
> Hi
>
> Use <div style='background: url("image.png");"> GWT can help you
> writing this code.http://code.google.com/webtoolkit/doc/latest/DevGuideClientBundle.htm...
>
> Other option is to try to prevent the browser for taking the default
> action. (I did not try myself)
>
> image.addClickHandler(new ClickHandler() {
>         public void onClick(ClickEvent event) {
>                 event.preventDefault();
>         }
>
> });
>
> Regards
> -Fran
>
> On Jun 4, 10:51 am, "Erik M." <erik.rost...@googlemail.com> wrote:
>
> > Hi,
>
> > I've got several Image Widgets on my Site. Is there a way to prevent
> > theselectionwith the mouse?Selectionof an image means its getting

rudolf michael

unread,
Jun 7, 2010, 12:12:37 PM6/7/10
to google-we...@googlegroups.com
or you can simply stop creating new Image() and use element.getStyle().setBackgroundImage() instead. much cleaner this way.

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.


Reply all
Reply to author
Forward
0 new messages