Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I add a <br/> and links to a javascript alert?

Tags:

javascript

I have the following statement:

btnApply.Attributes.Add("onclick", "alert('Must be a member to Use this Tool')"); 

Is there a way to add a new line. I tried, but it showed the in the text. In addition, can I add a link that would close the alert and take the user to another page?

How can I do this with my example?

When I added the \n, the alert doesn't show up.

like image 863
Xaisoft Avatar asked Feb 26 '09 15:02

Xaisoft


People also ask

How do I add a br tag to an alert?

In the alert box, you can use “\n”, to break the sentence into a new line. If you want a linebreak in actual javascript, use the \n escape sequence. Do comment if you knew another way to break the sentence in a new line using JavaScript code or you have any doubts.

Can you put HTML in a JavaScript alert?

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

Can you customize alert JavaScript?

You can create a custom function that'll replace the native alert() box in the user's web browser. You'll do this from the window object, and the custom function will work as such: Set constants for the alert title and alert button text.


1 Answers

You can't use HTML, but you can add line breaks:

alert('line1\nline2'); 

If a rich modal popup is really what you want though, you can use jQuery's dialog feature and put whatever you want in there.

like image 181
Daniel Schaffer Avatar answered Oct 03 '22 06:10

Daniel Schaffer