Jayro
10-12-2005, 12:51 AM
How do you change the background color of selected text in IE? This following works in Firefox
body::-moz-selection { background: black; }
but what about IE? I tried
body::selection { background: black; }
but that doesn't work? Any insight would be much appreciated.
Jayro
10-12-2005, 04:58 PM
This doesn't work:
body::selection { background-color: black; }
Siddan
10-12-2005, 05:27 PM
doubt IE even has this option
Kravvitz
10-12-2005, 05:28 PM
IE does not support the CSS to do that. There might be some way to do this with JScript.
Jayro
10-12-2005, 05:39 PM
Okay, thanks. I'll start a thread in the Javascript forum to see if anyone knows how to do it.
Kravvitz
10-13-2005, 12:41 AM
You're welcome :)
I did some testing and I'm pretty sure that this is not possible to do in IE.
Feel free to try it for yourself.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title></title>
<script type="text/javascript"><!--
function ie_select() {
document.selection.createRange().execCommand('BackColor',false,'#f00');
}
document.onselectstart = ie_select;
document.onselectionchange = ie_select;
document.onmouseup = ie_select;
document.onmousedown = ie_select;
document.onclick = ie_select;
// -->
</script>
</head>
<body>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec scelerisque
purus vitae wisi accumsan fringilla. Aliquam nibh elit, imperdiet eu,
scelerisque at, condimentum eget, leo. Nam dolor. Etiam rutrum. Nullam nulla
nibh, sollicitudin in, dictum ut, ullamcorper id, mauris. Aenean ultricies,
erat quis aliquet pellentesque, sapien nulla posuere nunc, sed tincidunt wisi
wisi id quam. Donec magna ante, pellentesque eu, posuere sed, ultrices sed,
velit. Sed id velit. Quisque sollicitudin lacus a ante. Etiam aliquam. Nulla
vitae lectus. Mauris ante neque, blandit id, vehicula nec, iaculis vitae, wisi.
Mauris quis elit sed quam interdum sollicitudin. Curabitur congue egestas
velit. Nulla feugiat placerat felis. Praesent felis tellus, rutrum et, faucibus
eget, sagittis non, ligula. Fusce porta, lorem at convallis vehicula, arcu eros
egestas tellus, in bibendum ante metus vel nisl. Sed erat nulla, vulputate vel,
fermentum et, feugiat nec, eros. Pellentesque augue tortor, rutrum eu, mattis
id, ornare vitae, sapien.</p>
</body>
</html>
Not quite ... Click on a word or make a selection, then click on body
<script type="text/javascript">
<!--
function ie_select() {
var tr=document.selection.createRange();
tr.execCommand('BackColor',false,'#f00');
tr.select();
}
document.onmouseup = ie_select;
// -->
</script>
Jayro
10-13-2005, 12:49 PM
Fang, unfortunately your suggestion doesn't work. It only changes the backcolor of the text after it's no longer selected. What I need is to be able to set the backcolor of the selected text 'while' it is selected.