 |
| Javascript General Javascript discussions. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

June 22nd, 2005, 06:11 AM
|
|
Friend of Wrox
|
|
Join Date: Sep 2004
Posts: 103
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
non-selectable html?
Hi all,
How can I make a text or table in an html document non-selectable? In other words how can I prevent an html item to be selected(highlighted blue in IE) while pressing and draging the mouse on it?Is there any style to do the job?
|
|

June 22nd, 2005, 10:48 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
In IE you can set unselectable="on" in the body tag. You could also try ondragstart="return false;" in the body element.
--
Joe ( Microsoft MVP - XML)
|
|

June 23rd, 2005, 07:34 AM
|
|
Friend of Wrox
|
|
Join Date: Sep 2004
Posts: 103
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
What about other browsers?
|
|

June 23rd, 2005, 09:22 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
|
|
In Mozilla, Netscape, and Mozilla Firefox you can do something like this in a style sheet:
::-moz-selection {
background: transparent;
color: inherit;
}
That just makes the selection invisible, there is still a selection though.
Safari, I think, supports ::selection, therefore you can do this in Safari, and possibly Konquorer as well.
::selection {
background: transparent;
color: inherit;
}
Don't know though, haven't tested it.
Regards,
Rich
--
[ http://www.smilingsouls.net]
Mail_IMAP: A PHP/C-Client/PEAR solution for webmail
Author: Beginning CSS: Cascading Style Sheets For Web Design
|
|

June 26th, 2005, 02:24 AM
|
|
Friend of Wrox
|
|
Join Date: Sep 2004
Posts: 103
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks but I'm using the following code instead:
<html>
<head>
</head>
<body onload="window.setInterval('document.selection.emp ty()',100);">
some text
</body>
</html>
Not sure if there's any equivalant code for other browsers...
|
|

June 27th, 2005, 10:56 AM
|
 |
Wrox Author
|
|
Join Date: Dec 2004
Posts: 217
Thanks: 0
Thanked 5 Times in 5 Posts
|
|
What you actually want to do in Mozilla is this:
Code:
* {
-moz-user-select:none;
}
In IE, the best way to do it is to use onselectstart:
Code:
<body onselectstart="return false">
Nicholas C. Zakas
Author, Professional JavaScript for Web Developers (ISBN 0764579088)
http://www.nczonline.net/
|
|

June 27th, 2005, 11:07 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
Quote:
quote:Originally posted by nzakas
In IE, the best way to do it is to use onselectstart:
Code:
<body onselectstart="return false">
Nicholas C. Zakas
Author, Professional JavaScript for Web Developers (ISBN 0764579088)
http://www.nczonline.net/
|
Yes sorry nerssi, "onselectstart" was what I meant, not sure where "ondragstart" came from :)
--
Joe ( Microsoft MVP - XML)
|
|

August 5th, 2005, 05:04 AM
|
|
Friend of Wrox
|
|
Join Date: May 2004
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
ondragstart is in VBA :)
|
|

January 13th, 2008, 07:30 PM
|
|
Registered User
|
|
Join Date: Jun 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
1 javascript line solution:
firefox/mozilla/iexplore:
Code:
nonselectableobject.onmousedown = nonselectableobject.onselectstart = function(){return false;}
|
|
 |