0

I'm quite new to JavaScript and HTML. I'm trying to write a program that takes in a number and spits out garbled text (containing all sorts of special characters and symbols; here's a sample: @;f%UA@;f%UDaVI*&e"q+/[)).

My JavaScript code takes in an input number and generates a string of garbled characters, which is then displayed on a paragraph on the page (using document.getElementById("output").innerHTML) and simultaneously copied to clipboard. The program seems to work as intended for the most part, but whenever the garbled output string contains a left angular bracket (<), the text in the paragraph is not displayed completely.

Here's a sample output:

  • Garbled string: K@8K@<vI,= ]1h<r50\ `
  • Output in the page body: K@8K@

Even the above code formatting is broken at the left angular bracket <, which leads me to suspect that this may be caused by an escape sequence or something similar. I'd be very glad if someone can suggest a way to fix this issue with the text rendering.

3
  • 2
    This has nothing to do with “escape sequences”, but with the meaning < and > simply have in HTML. You don’t want what you created interpreted as HTML, you want it treated as text - so don’t use .innerHTML, use .innerText instead. Commented Jul 21, 2020 at 8:29
  • Thanks for the suggestion, I'll try this out in my code and get back. Commented Jul 21, 2020 at 8:31
  • Your suggestion works as intended. Thanks for the help. If you post this comment as an answer, I'll mark it as accepted. Commented Jul 21, 2020 at 8:34

2 Answers 2

4

For me, what fixed the issue was adding <meta charset="UTF-8" /> in the <head> section.

Sign up to request clarification or add additional context in comments.

Comments

2

This has nothing to do with “escape sequences”, but with the meaning < and > simply have in HTML.

The browser thinks you are stating an HTML tag with <… – and tags do not show on screen in HTML, they are part of the structure.

You don’t want what you created interpreted as HTML, you want it treated as text - so don’t use .innerHTML, use .innerText instead.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.