473,402 Members | 2,053 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

ondrag event equivalent for mozilla

Is there something that I can use to prevent the a user from dragging
something, an image for instance. In IE I can use the ondrag = "return
false;", is there a way to achieve the same way with the other browsers?

Thanks,

David
Aug 10 '05 #1
10 13889


David wrote:
Is there something that I can use to prevent the a user from dragging
something, an image for instance. In IE I can use the ondrag = "return
false;", is there a way to achieve the same way with the other browsers?


<img onmousedown="if (event.preventDefault) {
event.preventDefault();
}
return false;"
src="whatever.gif" alt="whatever">
should do.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Aug 10 '05 #2
Martin Honnen:

David wrote:
Is there something that I can use to prevent the a user from dragging
something, an image for instance. In IE I can use the ondrag = "return
false;", is there a way to achieve the same way with the other browsers?


<img onmousedown="if (event.preventDefault) {
event.preventDefault();
}
return false;"
src="whatever.gif" alt="whatever">
should do.

--


The problem with this is that I have the img tag nested inside a div tag
which needs to be clicked and not have the event cancelled. Any other
ideas?
Aug 11 '05 #3


David wrote:
Martin Honnen:
David wrote:
Is there something that I can use to prevent the a user from dragging
something, an image for instance. In IE I can use the ondrag = "return
false;", is there a way to achieve the same way with the other browsers?


<img onmousedown="if (event.preventDefault) {
event.preventDefault();
}
return false;"
src="whatever.gif" alt="whatever">
should do.


The problem with this is that I have the img tag nested inside a div tag
which needs to be clicked and not have the event cancelled. Any other
ideas?


You can still click the <div> outside of the <img>.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Aug 11 '05 #4
Martin Honnen wrote:
David wrote:

The problem with this is that I have the img tag nested inside a div tag
which needs to be clicked and not have the event cancelled. Any other
ideas?


You can still click the <div> outside of the <img>.


Ok, so let me clarify what I meant, I have the img tag nest inside a div tag
and the img tag click event NEEDS to bubble and not be cancelled. So is
there any other way to go about cancelling drag? If not, it's no big dealy,
just would be nice.

Thanks!
Aug 11 '05 #5
ASM
David wrote:
so let me clarify what I meant, I have the img tag nest inside a div tag
and the img tag click event NEEDS to bubble and not be cancelled. So is
there any other way to go about cancelling drag? If not, it's no big dealy,
just would be nice.


and adding

onmouseup="this.click();"

would it run ?
--
Stephane Moriaux et son [moins] vieux Mac
Aug 11 '05 #6

ASM wrote:
David wrote:
so let me clarify what I meant, I have the img tag nest inside a div tag
and the img tag click event NEEDS to bubble and not be cancelled. So is
there any other way to go about cancelling drag? If not, it's no big
dealy, just would be nice.


and adding

onmouseup="this.click();"

would it run ?


Heh, no, the mousedown, mouseup, and click events all need to bubble up to
the DIV tag, any other ideas? Thanks for bearing with me!

David
Aug 13 '05 #7


David wrote:

Ok, so let me clarify what I meant, I have the img tag nest inside a div tag
and the img tag click event NEEDS to bubble and not be cancelled. So is
there any other way to go about cancelling drag?


Well the event continues to bubble, what I suggested is to use
preventDefault() which prevents the default action but not
stopPropagation() which would prevent the event propagation.

Here is a short and simple test case for Mozilla and Opera 8:

<html lang="en">
<head>
<title>difference between preventDefault and stopPropagation</title>
<script type="text/javascript">
function output (tagName, text) {
var element = document.createElement(tagName);
element.appendChild(document.createTextNode(text)) ;
document.body.appendChild(element);
}
</script>
</head>
<body>

<h1>difference between preventDefault and stopPropagation</h1>

<h2>div element whith image which should not allow dragging</h2>

<div id="div1"
style="border: 1px solid green;"
onmousedown="output('p', 'div handles ' + event.type);"
onclick="output('p', 'div handles ' + event.type);"
onmouseup="output('p', 'div handles ' + event.type);">
<p>Here is a div with an img element where the normal drag operation the
browser offers is prevented:
<img src="kiboInside.gif" alt="Kibo inside"
onmousedown="if (event.preventDefault) {
event.preventDefault();
}">
</p>
</div>

<hr>

<h2>debug output of events</h2>

</body>
</html>
You will find that the <div> element containing the <img> will get any
events as events still propagate.

I think in my first answer I had also some return false in the event
handler but that should then not be used.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Aug 14 '05 #8
ASM
Martin Honnen wrote:

[snip interesting example page]

works fine with FF, Safari, Opera, Camino
but
IE5.2 (Mac), iCab3 yet allowes to catch (and drag) image ...

--
Stephane Moriaux et son [moins] vieux Mac
Aug 14 '05 #9


ASM wrote:
but
IE5.2 (Mac), iCab3 yet allowes to catch (and drag) image ...


For IE that is obvious as the example code only uses W3C DOM Level 2
Events code that neither IE on the Mac nor IE on Win support.
For IE/Win the original poster, David, already has a solution, I am not
sure off hand whether IE/Mac supports the ondrag handler and cancelling
the drag event.
No idea about iCab, I don't have it and there is not a lot of
documentation, I guess it might not support the event.preventDefault
method.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Aug 14 '05 #10

Martin Honnen wrote:


David wrote:

Ok, so let me clarify what I meant, I have the img tag nest inside a div
tag and the img tag click event NEEDS to bubble and not be cancelled. So
is there any other way to go about cancelling drag?


Well the event continues to bubble, what I suggested is to use
preventDefault() which prevents the default action but not
stopPropagation() which would prevent the event propagation.

Here is a short and simple test case for Mozilla and Opera 8:

<html lang="en">
<head>
<title>difference between preventDefault and stopPropagation</title>
<script type="text/javascript">
function output (tagName, text) {
var element = document.createElement(tagName);
element.appendChild(document.createTextNode(text)) ;
document.body.appendChild(element);
}
</script>
</head>
<body>

<h1>difference between preventDefault and stopPropagation</h1>

<h2>div element whith image which should not allow dragging</h2>

<div id="div1"
style="border: 1px solid green;"
onmousedown="output('p', 'div handles ' + event.type);"
onclick="output('p', 'div handles ' + event.type);"
onmouseup="output('p', 'div handles ' + event.type);">
<p>Here is a div with an img element where the normal drag operation the
browser offers is prevented:
<img src="kiboInside.gif" alt="Kibo inside"
onmousedown="if (event.preventDefault) {
event.preventDefault();
}">
</p>
</div>

<hr>

<h2>debug output of events</h2>

</body>
</html>
You will find that the <div> element containing the <img> will get any
events as events still propagate.

I think in my first answer I had also some return false in the event
handler but that should then not be used.


Ok, now I understand better, not sure why I thought that preventDefault()
kept the event from bubbling. Thanks a lot for the help!

David
Aug 16 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: yzzzzz | last post by:
Hi I have: <div onkeypress="go(event)">...</div> and: function go(event) { alert(event.keyCode); }
10
by: tony kulik | last post by:
This code works fine in ie and opera but not at all in Mozilla. Anybody got a clue as to how to get it right? <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <script...
5
by: Jeff Thies | last post by:
I have this IE specific bit of code for finding the originating node: var obj=window.event.srcElement; How do I do that cross browser (Opera, NS, Safari...)? Is there a standard DOM method? ...
3
by: Vikram Bhatia | last post by:
1. Is there an event to capture scrolling using mouse wheel in Netscape 6.x? 2. When arrow keys are used to scroll a page in Netscape 6.x, the scrolling offsets obtained using...
3
by: Lachlan Hunt | last post by:
Hi, I've been looking up lots of documentation and trying to work out a cross-platform method of capturing a keyboard event and working out which key was pressed. From what I can find, there...
3
by: Suresh | last post by:
I have a table. <table border=1> <tr> <td onmousedown="create(this)"></td> <td onmousedown="create(this)"></td> </tr> <tr> <td onmousedown="create(this)"></td> <td...
2
by: tfrancis | last post by:
Hi, I am trying to handle my mouse movements myself in my JavaScript application which is ok except for the following problem. If I happen to click on an image and then move the mouse, the...
6
by: Tom | last post by:
Hi, In the following code I have reproduced a problem in IE that is extremely annoying for my application. <html> <head> <script type="text/javascript">
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.