By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,608 Members | 1,940 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,608 IT Pros & Developers. It's quick & easy.

How to turn browser text-hilighting back on after disabling

P: 2
I'm working on some drag-n-drop javascript code for a web app, where the company requires all the users to be on Win XP, using IE 6 (so I don't care about cross-browser compatibility - lucky me!)

I've got the d-n-d code working, and I found code to use to turn off text selection while an object is being moved (which was just plain ugly.) However, I can't figure out how to turn text selection back ON after the object is dropped.

The code to stop the browser from selecting text is done like this:
Expand|Select|Wrap|Line Numbers
  1. document.onselectstart = new Function ("return false");
Is there a way for me to first save what document.onselectstart's function was set to? Like a getFunction(document.onselectstart)? OR, does someone know what the function is initially set to - or where I could find a reference that might have it?
Oct 11 '06 #1
Share this Question
Share on Google+
1 Reply

P: 2
Oh Jay Why, you simpleton.

Its as easy as creating a temporary function holder, any variable will do. Before setting the document to not hilight, just set your temp variable to the old function. When you're done, just set the documents onselectstart event to your temp var.

Here's some code, in case you're too daft to understand.
Expand|Select|Wrap|Line Numbers
  1. // create your var:
  2. var tempFunctionHolder;
  4. // in your drag start code, copy the function to your temp var, then 
  5. // overwrite the select text function:
  6. tempFunctionHolder = document.onselectstart;
  7. document.onselectstart = new function(return false);
  9. // when the object is dropped, put things back:
  10. document.onselectstart = tempFunctionHolder;
Welcome to coding for Kindergartners!

Sheesh... staring at a screen too long and made a problem more difficult than it was...
Oct 12 '06 #2

Post your reply

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