I'm trying to clear any text selection that may be active on the page, including selected text in a textbox. This works in Firefox and Chrome:
document.getSelection().removeAllRanges();
It also works in IE for text selected on the page, but not text selected in a textbox.
I was doing the following for IE, which worked for both types of selections, but it is no longer supported in IE11:
document.selection.empty();
Any ideas?
Figured it out. Call removeAllRanges() to deselect any selected text on the page, then add a new empty selection to deselect any selected text in the textbox. This covers all bases in all three browsers:
document.getSelection().removeAllRanges();
document.getSelection().addRange(document.createRange());
Related
There were some discussion in the past about disabling highlighting some parts of the selected text in Web pages, so the user is not able to visually select them (e. g. How to disable text selection highlighting using CSS?).
But they are still selected when the user selects it (e. g. with the adjacent text without the anti-highlighting protection).
So he or she press Ctrl+C to be surprised - the text in the clipboard is different from the selected one.
Is there some way to exclude a non-highlighted text from the selecting it, too?
Edited:
This problem manifests itself only in Chrome browser, other browsers don't select non-highlighted text (thanks to evolutionxbox) so my question is now:
How reach my goal for Chrome, too?
I am using autocomplete combo-box plugin in my form this work fine in all the browser except IE.
this code I am using
When I focus or type it populate option but when I select it does not set selected option in input box. this works fine in other browser firefox and chrome.
Please help me if I missed anything here.
Hello Stackoverflow I have a simple form validation logic that doesn't seem to work on IE7 for some reason.
Basically I have two dropdown boxes and an input box. When the first dropdown box state changes the other dropdown and inputbox clears.
Current this logic seem to work on FF, Chrome but not IE7. Also the clearing of the input box works as expected on IE as well.
$('#names').change(function(){
$('#rate').val("0");
$('#amount').val("");
});
Any helps would be greatly appreciated.
It seems IE requires you to add the null value in order to change it to the first element.
<option>--</option>
To
<option value="0">--</option>
Fixed the issue :)
I have an application with several tabs, each of them having couple of fields. The last tab is Preview tab wherein I would like to show all the controls from all tabs in grayed color in uneditable mode. To do that, I am taking innerhtml of all tabs and showing the same in Preview tab.
While this logic works fine for Text fields, Select fields and Radio fields are not retaining their selected options in Mozilla and Chrome. It works as expected in IE 7, 8 and 9 too.
Any clue on this?
Try using the clone() method to make a copy of it instead of using the innerHTML property.
Example in JSFiddle: http://jsfiddle.net/jLB5s/
I have a form with a special widget that fills in a text input. When the text input has focus, the widget appears above the text input (intentionally above it) and the user clicks options in it, when they're done it disappears and fills in the input. There is a problem with this in IE, when the widget appears above the input, the field's caret (blinking text input cursor for the field) shows through the widget. The widget is a normal html/css dom structure. It still does this when I set the z-index for the widget to be above the text input. How can I get rid of the caret or make sure it doesn't shine through?
I don't want to set the focus elsewhere for the duration that the widget is shown because the widget requires that the input has focus.
Try setting the unselectable attribute to on while the widget is being shown, then to off at the end. It's an IE specific attribute, and if it works you should check it in IE 8, as I'm not sure if it's still supported.
Seems to me that a simple blur on that field or focus on a field in the widget would fix your problem.