Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

html entities in a javascript alert?

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?

like image 358
markzzz Avatar asked Feb 18 '13 13:02

markzzz


People also ask

Can you put HTML in an alert box?

You can add HTML into an alert string, but it will not render as HTML. It will just be displayed as a plain string.

Can you customize JavaScript alert?

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.

Can we use alert in JavaScript?

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.

How do you alert something in HTML?

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.


2 Answers

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;
like image 181
Imperative Avatar answered Oct 21 '22 14:10

Imperative


var encoded = "This is à string";
var decoded = $("<div/>").html(encoded).text();
alert(decoded);
like image 34
gregjer Avatar answered Oct 21 '22 16:10

gregjer