Multi-line email body in JSX - javascript

I am trying to create an email with a multi line body using:
<a href={"mailto:" + this.state.emailsToNotify +
"?subject=" + this.state.mname
+ "&body=Please, review: " + "\n" + this.state.mname + "\n" + "at " + emailBody
}>
<button style={button4TableStyleObject('#007a86', '#ebf5ff', '#ff3900 #ff3900')} >{'Notify Selected'} </button>
</a>
However Outlook opens this email using a single line. Is there a way to make it multi-line? I used "\n" with double quotes but no luck.

You have to encode the parameters you pass in a mailto: url. For a line break, you can use %0A:
your message here
In order to not have to do this manually, you can use encodeURIComponent():
console.log(encodeURIComponent(`first line
second line
paragraph`));

Related

Setting a href inside of template literals

I'm trying to make use of a nice email template for when a user signs up with their email, I'm using express & node mailer to accomplish this. Previously my code looked like:
"Hello, " +
user.username +
",\n\n" +
"Please complete your registration by clicking the link:
\nhttp://" + req.headers.host + "/confirmation/" + user.username + "/" + token.token +
"\n\nThank you!\n"
Inside of my HTML template, which is a template literal ive tried this:
const output = ` <a href="${req.headers.host} + "/confirmation/" + ${user.username} + "/" + ${token.token}" `
but this doesn't work, theres no href on the <a> inside of the email.
I must be missing something really basic... thanks for looking =)
With `` you don't need to concatenate the string with +, so it should look like this:
const output = ``

\n or <br\> is not working in javascript

I am setting value of hiddenfield from code behind in vb.net
If(condition)
hdmodulename.Value =Dt_Module.DefaultView(0).Item("vModuleCode").ToString() +
"-" + Dt_Module.DefaultView(0).Item("vModuleName").ToString()
Else
hdmodulename.Value = hdmodulename.Value + "'\n'" + Dt_Module.DefaultView(0).Item("vModuleCode").ToString() + "-" + Dt_Module.DefaultView(0).Item("vModuleName").ToString()
End If
now alert in javascript
i code like below:
alert('You cannot select ' + document.getElementById('<%=hdmodulename.ClientID%>').value);
Output :
'\n' is printed inseted of new line
so what is the probem??
Thanks A ton in advance
As for web pages, break lines with <br> or <p></p> tags. You can also Use Environment.NewLine with VB.
For JS use \n' for the line break -
alert("some text\nmore text in a new line");
Please try with Environment.NewLine for VB.net
as below:
Dim value As String = "[First" + _
Environment.NewLine + _
"Second]"
will return
[First
Second]
Not a vb expert, but shouldn't it be "\n" instead of "'\n'"?
The one in the vb code have both double and single.

Add a "new line" in innerHTML

I am trying to create a table with images in first cell and information about the pic in second cell.
I need to add different information in one cell, like that:
cellTwo.innerHTML = arr_title[element] + arr_tags[element];
Is it possible to add a "new line" there?
I mean like that:
cellTwo.innerHTML = arr_title[element] + "/n" + arr_tags[element];
The simplest way is by adding a line break as html
cellTwo.innerHTML = arr_title[element] + "<br />" + arr_tags[element];
If you want your newlines to be treated literally, you could use the <pre> tag
cellTwo.innerHTML =
"<pre>" + arr_title[element] + "\n" + arr_tags[element] + "</pre>";
To round out your understanding:
Since it is html (innerHTML) it renders html and you can use any html you wish, so in this case simply add an good old fashioned <br>:
var test = document.getElementById('someElementId');
test.innerHTML = "The answer <br>to life, the universe, and everything...<br> is 42.";
If it were a string, such as in an alert box or text box etc. then /n would be correct:
alert('Never /n Forget your towel.');
Happy Coding!
- $cr1ptN!nj#
No, <br /> does not work in asp .net but you can instead write it like so
cellTwo.innerHTML = arr_title[element] + arr_tags[element]; arr_title[element] + "/n" + arr_tags[element];
Edit - alternative wrapped in code tags
cellTwo.innerHTML = arr_title[element] + arr_tags[element];
cellTwo.innerHTML += arr_title[element] + "/n" + arr_tags[element];
Semicolon ";" seems to act as line breaks
Remember the "+=" to assign multiple values to the string

Create a link with javascript within it

so I am trying to create a link within my page but for some reason it is getting disjointed the code is
data = data + "<li><a href='#' onclick='History.pushState({state:null},'article,"+rtndata[j].id+"','article'); return false;'>" + rtndata[j].title + "</a></li>";
rtndata[j].id is an id number and rtndata[j].title is a title both are being pulled from a db but when it renders in the browser it becomes
<a false;'="" return="" article,41','article');="" onclick="History.pushState({state:null}," href="#">Newsflash 5</a>
so what I to render is actually
<a href="#" onclick="History.pushState({state:null},'article,41','article'); return false;'>"Newsflash 5</a>;
Can anyone help me?
The value of the onclick attribute is enclosed within single quotes. Because of this, you have to either use " or " (only for values) if you have to use quotes inside the attribute.
Because your JavaScript string is enclosed within double quotes ("), the double quotes have to be escaped before they can be used: "....onclick='...\"....'....";.
To fix your code, I have decided to use double quotes (escaped) instead of single quotes:
data = data + "<li>" + rtndata[j].title + "</li>";
Detailled table:
JS string marker Attribute marker Valid attribute value markers
" \" ' "
" ' \" "
' " \' "
' \' " "

Blinking page title

I'm trying to get some notifications working for AJAXChat. To do this all I want to do is get the title of the page to blink until focused. To do this I'm using the jquery-titlealert plugin. The problem is the html that is generated for the onload event is generated inside a js file shown here
return '<div id="'
+ this.getMessageDocumentID(messageID)
+ '" class="'
+ rowClass
+ '">'
+ this.getDeletionLink(messageID, userID, userRole, channelID)
+ dateTime
+ '<span class="'
+ userClass
+ '"'
+ this.getChatListUserNameTitle(userID, userName, userRole, ip)
+ ' dir="'
+ this.baseDirection
+ '" onload="$.titleAlert('New Message');">'
+ userName
+ '</span>'
+ colon
+ this.replaceText(messageText)
+ '</div>';
return
When I use this, it breaks the page. If I replace ('New Message') with (New Message) the page loads again but the notification isn't working. I think this is because its displaying a Javascript function inside Javascript. Anyone see anything here I'm missing?
Have you tried escaping your quotes? I.e.:
+ '" onload="$.titleAlert(\'New Message\');">'
Any single quote (') inside a single quoted string (or double quote (") inside a double quoted string) needs a backslash (\) before it. See the MDN String Literals documentation for more information about strings and proper character escaping.
You need to escape the quotes.
Change this
'" onload="$.titleAlert('New Message');">'
to this
'" onload="$.titleAlert(\'New Message\');">'
Try escaping the apostraphe's correctly:
+ '" onload="$.titleAlert(\'New Message\');">'

Categories

Resources