473,769 Members | 5,878 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Not selectable HTML, with exceptions

1 New Member
Hi there,

I have a quick, but apparently quite complicated question.

I want my whole site to be unselectable, with a few exceptions. Unfortunatly I am not able to do this.

I have a semi working versions, with onselectstart=" return false" in the body tag, but then I can't select anything. I also have a version with a function which iterates over the whole HTML and makes everything with "unselectab le" in the class name unselectable by:

Expand|Select|Wrap|Line Numbers
  1. function unselectElement(element) {
  2.     element.style.MozUserSelect='none';
  3.     element.style.KhtmlUserSelect='none';
  4.     element.unselectable='on';
  5.     element.onselectstart = function(){return false;};
  6. }
However, this application is extremy AJAX heavy and updated elements loose those assigned attributes/events. I'm using wicket where I would have to append javascript all the time for every single element which appears to be extremly tedious and requires resturucturing of the code as well. (if you have a good solution in this regard, tell me).

Unfortunatly I can't let the "unselectAl l" function run after every ajaxrequest, because it's just to slow.

Ideally I could specify that the whole document is unselectable and turn it on for the few elements I want the user to select. Preferably with CSS; but apparently this isn't possible.

An IE-only solution is okay right now, but cross browser solution would be awesome (FF and IE at least).

The reason for this functionality is mostly that I have a lot of dragable objects, which causes a bunch of elements in the background to be selected which looks more than ugly and is confusing for the user. I toy with a "body = unselectable" solution when something is dragged, but it's more of a last resort.

Help would really be much appreciated.

- Tom
Aug 21 '08 #1
2 2971
acoder
16,027 Recognized Expert Moderator MVP
Instead of making the whole page non-selectable, why not prevent the dragging of those elements only? That should solve this problem unless I've missed something. In your drag event handler, just check that only the correct elements/objects are allowed to be dragged.
Aug 21 '08 #2
mrhoo
428 Contributor
To prevent the body (or other container) content from being selected when you drag an item, stop the mousedown and mousemove events from bubbling up to the body.

Add the event stopping code at the end of the handlers:
Expand|Select|Wrap|Line Numbers
  1. function dragmove(e){
  2.     e=window.event || e;
  3.     // run your dragging code 
  4.  
  5.     event.cancelBubble= true;     //ie
  6.     if(e.stopPropagation) e.stopPropagation();     //others
  7. }
Aug 21 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

71
6505
by: tomy_baseo | last post by:
I'm new to HTML and want to learn the basics by learning to code by hand (with the assistance of an HTML editor to eliminate repetitive tasks). Can anyone recommend a good, basic HTML editor that's a step beyond Notepad (not a WYSIWYG tool). Thanks.
2
4706
by: Paul | last post by:
Hello, I am trying to make a menu for a html page and I am using DIV tags for buttons. I don't like the idea of being able to select the text, is there a way I can change this behaviour to make the text non-selectable? Advice for any browser appreciated. TIA Paul.
2
3330
by: Rachel Suddeth | last post by:
Is there a way to have the non-selectable dates (those before MinDate and after MaxDate) draw differently so my users can see right away what dates aren't allowed? I'm not seeing it... Otherwise, anyone know of a cheap 3rd party calendar control I could use that would provide that ability? Thanks, Rachel
5
5044
by: Samuel | last post by:
Hi, I am running into a problem of mixing UICulture = auto and allowing users to select culture using a dropdown list. I am detecting a querystring, "setlang", and when found, setting the CurrentUICulture to what's specified in the querystring. Since I want to allow UICulture auto detecting, I add UICulture = "auto" to page directive on each page.
8
1593
by: Gary Owsiany | last post by:
Ok, the silence is deafening. I posted my selectable sort application to show that you can use the IComparable Interface just as effectively as the IComparer Interface and the feedback has been, well, there hasn't been any feedback. Does that mean I have silenced my critics? Are you so overwhelmed by my programming prowess that I have left you speechless? Or do you think it is so bad, that it's not worth responding to? Chris Dunaway,...
40
2977
by: Paul Davis | last post by:
Hi all, I'm building some style sheets and trying to play the old game of balancing designer pixel perfection and still allowing users to adjust their font sizes. The compromise I've made with the designer is that he'll accept allowing users to change font sizes it it "looks right" with the default setting. I'm using em to set the font size. So, anyway, here's the problem. At 0.96em we get the perfect font size. But, if the font is...
1
2771
by: Homer | last post by:
Hi, I used a template for my first Web application. I made a few changes to the layer thru its css file. The problem that has been vexing me is the vertical spacing for each navigation menu item. If I do not set the verticalpadding property, the items are rendered too close to one another. However, when I set the verticalpadding property, I get the spacing that I want but the selectable area within each item is the exact height of...
1
1881
by: dbphoto | last post by:
I've created a selectable layer and inputted the action script into the button but the layer appears on the main layer and is not selectable. Any ideas?
2
3256
by: DMVC | last post by:
Hi all. I've built a class based on "Control" and I want this object of mine to be selectable. I believe that, by default, Control is non-selectable so I used this.SetStyle(ControlStyles.Selectable, true); And it works fine when I use TAB key, but when I click on my object, the focus remains on the current object. What am I doing wrong?
0
9589
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
9423
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
10215
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9996
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
9865
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
8872
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7410
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6674
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();...
2
3564
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.