I have a string coming from a XML (which I can't edit) and I'd like to print it trough an alert in javascript.
Example of my string:
This is à string
And I need to print in an alert:
This is à string
is there a js html decode?
You can add HTML into an alert string, but it will not render as HTML. It will just be displayed as a plain string.
The standard alert box in JavaScript does not provide the option to apply CSS. To style your alert box, you need to create a custom one first. The custom alert box will be created using jQuery and styles will be applied to CSS.
One useful function that's native to JavaScript is the alert() function. This function will display text in a dialog box that pops up on the screen.
The Window alert() method is used to display an alert box. It displays a specified message along with an OK button and is generally used to make sure that the information comes through the user. It returns a string which represents the text to display in the alert box.
you could put the string in a dom element and read it out again, even without jquery: https://stackoverflow.com/a/3700369/1986499
Edit by recent demand to include some code from another SO answer:
var div = document.createElement('div');
div.innerHTML = encoded;
var decoded = div.firstChild.nodeValue;
var encoded = "This is à string";
var decoded = $("<div/>").html(encoded).text();
alert(decoded);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With