Skip to content
Advertisement

No-break spaces are turned into normal spaces after copy & paste

I want to copy and paste a no-break space character from this website:

http://www.fileformat.info/info/unicode/char/00a0/browsertest.htm

The space is actually a NBSP, as we can see in the markup:

enter image description here

But when I select the space char on the website, copy and paste it into a string in Chrome Dev Tools and return the char code, I get the number 32:

var space = " "
space.charCodeAt(0)   // 32

32 is the char code for a normal space, I expected the number 160. Why has the NBSP become a normal space?

PS: I’m on Windows 10 and tried copying from Chrome 62 and Firefox 56.0.2 into their respective developer consoles.

Advertisement

Answer

It is not “normal”, but it is a well-known bug in both Gecko (Firefox) and Blink (Google Chrome). As indicated in the ticket which john c. j. referred to, Firefox 103 partly fixed this, but the behavior remains unchanged in the situation you described. Firefox issue #1769534 tracks the remaining problem.

Wikipedia’s article about non-breaking spaces lists some ways to type the character directly, including Alt+255 on Microsoft Windows.

Advertisement