Advanced Search

Results 1 to 8 of 8

Thread: Disable Drag and Drop

  1. #1
    Join Date
    May 2006
    Location
    Alaska
    Posts
    163
    Thanks
    5
    Thanked 2 Times in 2 Posts

    Default Disable Drag and Drop

    To be blunt: How do you disable drag and drop for an HTML Element? Specifically a DIV, but it shouldn't matter. I'm making buttons, and it would be kinda lame if people could drag them around... I could do a whole messy thing with an overlay div and pass the click and move events through to the buttons, but I'd rather not. If you want my code you can have it, but I don't think it's necessary.

    Thanks,
    Stephen

  2. #2
    Join Date
    Jan 2008
    Posts
    4,158
    Thanks
    28
    Thanked 623 Times in 619 Posts
    Blog Entries
    1

    Default

    What are you referring to? HTML elements aren't draggable.
    Jeremy | jfein.net

  3. #3
    Join Date
    May 2006
    Location
    Alaska
    Posts
    163
    Thanks
    5
    Thanked 2 Times in 2 Posts

    Default

    I have DIVs that have a dynamically changed background image and in FF I can drag them.

  4. #4
    Join Date
    Jun 2008
    Posts
    589
    Thanks
    13
    Thanked 54 Times in 54 Posts
    Blog Entries
    1

    Default

    That's what I thought. I was going to point out that you can drag things in FF (most of the time, images). It is near impossible to disable this. Do you not want people to save your images? More info and as to why you want this is perfectly acceptable and wanted.
    Last edited by magicyte; 12-24-2008 at 11:58 PM.

  5. #5
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,674
    Thanks
    43
    Thanked 3,125 Times in 3,091 Posts
    Blog Entries
    12

    Default

    Please post a link to the page on your site that contains the problematic code so we can check it out.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  6. #6
    Join Date
    May 2006
    Location
    Alaska
    Posts
    163
    Thanks
    5
    Thanked 2 Times in 2 Posts

    Default

    I don't have a site, I can give you the code, but I didn't think it'd be necessary. It's not that I don't want people to get my images, I'm all for having things available for everyone, but this is a button. It looks kinda lame if they can drag it, and it screws up my events.

  7. #7
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,674
    Thanks
    43
    Thanked 3,125 Times in 3,091 Posts
    Blog Entries
    12

    Default

    It wasn't very clear what the trouble was. It still isn't. By default, there is no drag and drop. Some browsers allow you to drag and drop images to save them, but not to rearrange them on the page. As far as divisions go, they also may sometimes be able to be dragged around, but not dropped or even saved (at least not that I've ever seen). When doing so with images some browsers even show a slightly lighter representation of the image being dragged, as a visual cue that 'you have it' in your mouse's 'clutches'.

    Now this may vary on other OS's, but in windows this may be prevented, at least in FF (the only browser that allows this anyway, and one of the few in which your code seems to work as intended) by:

    Code:
    			window.onmousedown = function(e){
    			if(e && e.preventDefault)
    			 e.preventDefault();
    			};
    But none of this really hurts anything, and FF users expect to be able to do this, and generally won't unless they want to save the image, which can be done many other ways if this is disabled, so I would leave it alone.

    This (below) however appears useless, and messes things up in Google Chrome (all others appeared to ignore it):

    Code:
    					btns [id].ondrag = function () {
    						alert ("dragging");
    						return false;
    					}
    					btns [id].onenterstart = function () {
    						alert ("dragging");
    						return false;
    					}
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  8. #8
    Join Date
    May 2006
    Location
    Alaska
    Posts
    163
    Thanks
    5
    Thanked 2 Times in 2 Posts

    Default

    Hey, your right. It doesn't even work in IE. I guess I can just make an overlay. Well thanks.
    Stephen

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •