0

I am in chrome browser. I have blue background and the color of text is white.

Problem:

When i select and copy the text and paste in word, the text cannot be seen because of being.

Is there any javascript to change the text color when selected so that the copied text is not white.

Similar Question found:

Javascript: How to detect if a word is highlighted

Community
  • 1
  • 1

3 Answers3

2

As an alternative to JavaScript, how about using CSS to set the ::selection color (i.e. the color of the background highlighting)?

If your current background is blue and the default selection highlight color is blue, try changing the color to a red:

::selection {      /* WebKit Browsers */
  background: #ffb7b7;
}
::-moz-selection { /* Gecko Browsers */
  background: #ffb7b7;
}
newfurniturey
  • 37,556
  • 9
  • 94
  • 102
1

Probably some problems here, but it works in Chrome:

document.addEventListener('copy', function() {
    event.preventDefault();
    event.clipboardData.setData("text/plain", document.getSelection().toString());
}, false);
Martin
  • 171
  • 1
  • 8
0

Finally got this,

My solution was,

        var x = document.getElementById("elementID");
        function eventCopy() {
            x.style.color = 'black';
            x.addEventListener("mousemove", eventDispatch);
        }
        function eventDispatch() {
            x.style.color = 'white';
            console.log('h');
            x.removeEventListener("mousemove", eventDispatch);
        }
        x.addEventListener("copy",eventCopy);