473,664 Members | 2,972 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I make a piece of text in HTML non-selectable, but draggable?

A piece of text on my HTML page is framed with DIV tags.

While I want to be able to drag/drop it, I don't want it to be
selected, since it interferes with dragging.

I'd like to press a mouse key and drag it. Instead I start selecting
the text and keep going down selecting everything underneath. So in
order to actually drag, I have to Double-Click it first, and only
after it allows me to drag.
Do you know what I mean?

If I do
<DIV OnSelectStart=' return false;'>inner text i want to drag</DIV> <-
it allows me neither selection, nor dragging

What I want works fine with links, but not with pieces of text.
I need to be able to do the dragging of the inner text without
selection.

Is there any simple way?
Jul 20 '05 #1
2 20472
what you can do is when the user presses the mousebutton (onmousedown) you
can select the text (using textrange objects) and then when the user will
move his mouse the ondragstart event will fire. an example of how to
implement this follows:

<style>.clsSpan Drag { background-color: yellow }
</style>
<script>
window.onload = function()
{
var el = document.getEle mentById("mySpa n");
el.onmousedown = function()
{
var r = document.body.c reateTextRange( );
r.moveToElement Text(el);
r.select();
}
el.ondragstart = function(){aler t("test")}
}
</script>
</head>

<body>
<p>this is a test <span class="clsSpanD rag" id="mySpan">thi s is a
test</span> this is a test
</body>

hope this helps

etan
"Big Bolt" <bi******@hotma il.com> wrote in message
news:3c******** *************** ***@posting.goo gle.com...
A piece of text on my HTML page is framed with DIV tags.

While I want to be able to drag/drop it, I don't want it to be
selected, since it interferes with dragging.

I'd like to press a mouse key and drag it. Instead I start selecting
the text and keep going down selecting everything underneath. So in
order to actually drag, I have to Double-Click it first, and only
after it allows me to drag.
Do you know what I mean?

If I do
<DIV OnSelectStart=' return false;'>inner text i want to drag</DIV> <-
it allows me neither selection, nor dragging

What I want works fine with links, but not with pieces of text.
I need to be able to do the dragging of the inner text without
selection.

Is there any simple way?

Jul 20 '05 #2
Thanks guys for your prompt response!

Etan - worked like a charm, people will love it tomorrow.
I spend the whole last night trying different tweaks to make it work.

-------------- Here's how it finalized --------------------------
<div style="cursor:h and;" id=myId OnMouseDown='Mo useDown()'
OnDragStart='Dr agStart()'>my bloody text</div>

<script>
function OnMouseDown() {
var obj = window.event.sr cElement;
var r = document.body.c reateTextRange( );
r.moveToElement Text(obj);
r.select();
return true;
}

function OnDragStart() {
event.dataTrans fer.effectAllow ed = "all";
return true;
}
</script>
-----------------------------------------------------------------

The power if Internet amazes me!
"Etan Bukiet" <eb*****@comcas t.net> wrote in message news:<Ol******* *******@tk2msft ngp13.phx.gbl>. ..
what you can do is when the user presses the mousebutton (onmousedown) you
can select the text (using textrange objects) and then when the user will
move his mouse the ondragstart event will fire. an example of how to
implement this follows:

<style>.clsSpan Drag { background-color: yellow }
</style>
<script>
window.onload = function()
{
var el = document.getEle mentById("mySpa n");
el.onmousedown = function()
{
var r = document.body.c reateTextRange( );
r.moveToElement Text(el);
r.select();
}
el.ondragstart = function(){aler t("test")}
}
</script>
</head>

<body>
<p>this is a test <span class="clsSpanD rag" id="mySpan">thi s is a
test</span> this is a test
</body>

hope this helps

etan
"Big Bolt" <bi******@hotma il.com> wrote in message
news:3c******** *************** ***@posting.goo gle.com...
A piece of text on my HTML page is framed with DIV tags.

While I want to be able to drag/drop it, I don't want it to be
selected, since it interferes with dragging.

I'd like to press a mouse key and drag it. Instead I start selecting
the text and keep going down selecting everything underneath. So in
order to actually drag, I have to Double-Click it first, and only
after it allows me to drag.
Do you know what I mean?

If I do
<DIV OnSelectStart=' return false;'>inner text i want to drag</DIV> <-
it allows me neither selection, nor dragging

What I want works fine with links, but not with pieces of text.
I need to be able to do the dragging of the inner text without
selection.

Is there any simple way?

Jul 20 '05 #3

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

Similar topics

3
6152
by: Randell D. | last post by:
Folks, I'm still learning javascript - I've invested in a couple of books and reading online as much as possible. I'm pretty sure what I am suggesting is possible though I'm trying to weigh up the faults that might go with the suggestion... all opinions welcome. My question: I have a list of links that go to pages that have a similar layout. Could I have a text swap, similar to what I've seen with image swaps (or an image switch)...
4
6941
by: Cat Laugel | last post by:
Hello, I am redesigning my website and would like to have the text scroll within the webpage without the page itself scrolling.... if you understand what I mean... ;-) I want a very sleek look and would like to use little arrows that people could press to see more of the text rather than have a very long page.... How should I go about that? I use DW3. Can it be done???? Thanks for any info!! ;-)
16
7530
by: laura | last post by:
Can anyone help me to decide the best way to do this please. I'm writing an intranet and I need to put something like a non-editable scrolling text box on the home page where daily announcements can be placed. I've tried adding a scrolling text box, but I am not sure how to make it non-editable. Is there any way I can fill the textbox using something like textstream? I would imagine one person in the organisation would be in charge of...
56
3537
by: Rob Dob | last post by:
VS2005 is a PIECE of Garbage and is bug Ridden, I wonder how many others feel the same, I am so sorry that I have moved away from VS2003, VS2005 is unstable, and half the stuff doesn't work, Microsft has spent so much time trying to make it simply that when you try to do something useful with it it doesn't work... Half the time it crashes, and menu items appear for things you cannot do. For example, Go into component designer, ...
2
1891
by: sasperilla | last post by:
Hi, I would like to find the coordinates of a word inside a div or span tag. I know you can find the coordinates of a tag inside the DOM, but can you get the coordinates of a portion of the text inside that element in javascript? If the user highlights or selects text in a div or span can I get the indicies that make up that selected piece of text? What API of
1
1668
by: Sjef | last post by:
I am trying to understand the deeper meanings of containers. One would say: everything inside the container div will stay inside, but apparently that's not true. My test code is below. When I run this in IE everything seems fine, when I run it in Firefox the text runs out of the right box and the right box runs out of the overall container. I don't understand the reason for this??? I would like to make both columns the same height while...
7
3474
by: gregincolumbus | last post by:
Hello I have used chained selects to populate two selects. When the user chooses from first select, he is presented with the populated data for the 2nd select. The result is a list of numbers. The number varies with the choice made in the first select. Here is the config.js var hide_empty_list=true; addListGroup("registration", "category");
6
1299
by: Jianwei Sun | last post by:
I am reading a peice of code which is at the following link: http://www.brpreiss.com/books/opus4/html/page141.html#SECTION007123000000000000000 The code is like this: Object& StackAsLinkedList::Pop() { if(count==0) throw domain_error("stack is empty");
0
1111
by: Jianwei Sun | last post by:
Hello Alf, Thank you, and I like "that could be like interpreting as favorably as possible the writings of a chimpanzee posing as a college professor.". However, I will still read this book, with more attention to the c++ code. J.W.
1
1869
by: rh.krish | last post by:
Hi, I have a unique situation. We have many applications (approx - 20) built on .NET framework 1.1 & 2.0 and hosted in one single IIS website in PROD. We have similar setup in TEST. Now we want to have a banner indicating that the website being accessed by the user is TEST. This is because, there are some users who have access to both and sometimes they do stuffs in PROD which are meant to be done only in TEST. By displaying somekind of...
0
8437
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8348
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8778
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8549
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8636
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5660
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4185
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2764
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2003
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.