Nasser
Nasser

Reputation: 2140

Including a link in reponse.write

When I run the following code:

res.write("Author: ");
res.write("<a href='" + tweet[i].Link + "' target='_blank'>" + tweet[i].Lable + "</a> \n");
res.write("Date: " + tweet[i].TDate  + "\n");

I got this:

Author: <a href='https://twitter.com/esti_palombo' target='_blank'>esti_palombo</a> 
Date: 2016-03-12T00:00:00.000Z
Author: <a href='https://twitter.com/AbdElrazek_Esam' target='_blank'>AbdElrazek_Esam</a> 
Date: 2016-03-08T00:00:00.000Z

As you can see, the links do not work

But when I remove the first line res.write("Author: "); :

esti_palombo Date: 2016-03-12T00:00:00.000Z AbdElrazek_Esam Date: 2016-03-08T00:00:00.000Z

links are working fine but the new line \n does not work !!

Can someone help me with this

Upvotes: 0

Views: 22

Answers (2)

Blindy
Blindy

Reputation: 67380

By refusing to write a proper header, you're forcing the browser to guess it for you. As you can see, simply changing the format of your data is making it guess differently.

Set the content type to text/html and you'll be in the second case of your post, and since you're writing HTML you don't use newlines to break lines, you use paragraphs or line breaks (<br>).

Upvotes: 2

Denny Mathew
Denny Mathew

Reputation: 1132

Please try by replacing '\n' with <br/>

Upvotes: 0

Related Questions