Proper handling text that was sent via JSON when returning html string and inserting it into tittle attributeASP.NET MVC controller actions that return JSON or partial htmlHTML-encoding lost when attribute read from input fieldHow to remove line breaks from a file in Java?Selecting all text in HTML text input when clickedProper way to return JSON using node or ExpressGet Attributes of enclosing Tag in HTML StringHow to prevent CKEditor to add a space ( )?How to escape a concatenated string in html title attributeinsert attributes dynamically in html elements in angularHow to prevent html attribute value from generating new line, my json string value breaks
GFCI outlets - can they be repaired? Are they really needed at the end of a circuit?
Im going to France and my passport expires June 19th
How did the Super Star Destroyer Executor get destroyed exactly?
Bullying boss launched a smear campaign and made me unemployable
Avoiding the "not like other girls" trope?
How seriously should I take size and weight limits of hand luggage?
What about the virus in 12 Monkeys?
What is the most common color to indicate the input-field is disabled?
Why do bosons tend to occupy the same state?
How would I stat a creature to be immune to everything but the Magic Missile spell? (just for fun)
Why doesn't using multiple commands with a || or && conditional work?
Why is consensus so controversial in Britain?
How do I gain back my faith in my PhD degree?
Why would the Red Woman birth a shadow if she worshipped the Lord of the Light?
What mechanic is there to disable a threat instead of killing it?
Are there any examples of a variable being normally distributed that is *not* due to the Central Limit Theorem?
How can saying a song's name be a copyright violation?
How dangerous is XSS?
Avoiding direct proof while writing proof by induction
How does a predictive coding aid in lossless compression?
Plagiarism or not?
Reverse dictionary where values are lists
How could indestructible materials be used in power generation?
What exploit Are these user agents trying to use?
Proper handling text that was sent via JSON when returning html string and inserting it into tittle attribute
ASP.NET MVC controller actions that return JSON or partial htmlHTML-encoding lost when attribute read from input fieldHow to remove line breaks from a file in Java?Selecting all text in HTML text input when clickedProper way to return JSON using node or ExpressGet Attributes of enclosing Tag in HTML StringHow to prevent CKEditor to add a space ( )?How to escape a concatenated string in html title attributeinsert attributes dynamically in html elements in angularHow to prevent html attribute value from generating new line, my json string value breaks
i have the following text (with new lines).
"☢☢☢☢2222def l2 ❤ ☀ ☆ ☂ ☻ ♞ ☯ ☭ ☢ € → ~`!@#$%^&*()_+-=[]\|:;"'<>?,./ 1 ❤ ☀ ☆ ☂ ☻ ♞ ☯ ☭ ☢ € → ~`!@#$%^&*()_+-=[]\|:;"'<>?,./ 2 ❤ ☀ ☆ ☂ ☻ ♞ ☯ ☭ ☢ € → ~`!@#$%^&*()_+-=[]\|:;"'<>?,./def l2 ❤ ☀ ☆ ☂ ☻ ♞ ☯ ☭ ☢ € → ~`!@#$%^&*()_+-=[]\|:;"'<>?,./ 1 ❤ ☀ ☆ ☂ ☻ ♞ ☯ ☭ ☢ € → ~`!@#$%^&*()_+-=[]\|:;"'<>?,./ 2 ❤ ☀ ☆ ☂ ☻ ♞ ☯ ☭ ☢ € → ~`!@#$%^&*()_+-=[]\|:;"'<>?,./"
122434 *()_+-=[]\|:;"'<>?,./def l2 ❤ ☀ ☆ ☂ ☻ ♞ ☯ ☭ ☢ € → ~`!@#$%^&*()_+-=[]\|:;"'<>?,./ 1 ❤ ☀ ☆ ☂ ☻ ♞ ☯ ☭ ☢ € → ~`!@#$%^&*()_+-=[]\|:;"'<>?,./ 2 ❤ ☀ ☆ ☂ ☻ ♞ ☯ ☭ ☢ € → ~`!@#$%^&*()_+-=[]\|:;"'<>?,./"
I use datatbles.js and there when populating cells i have a function that returns an html string
return '<span title="TEXT"></span>'
When i do this
return '<span title="'+text+'"></span>'
Or this
return '<span title="'+JSON.stringify(text)+'"></span>'
It breaks my returned element.
How could I approach inserting the text above with new lines etc. to the title
attribute so it would work properly?
Thank you!
javascript json string datatable datatables
add a comment |
i have the following text (with new lines).
"☢☢☢☢2222def l2 ❤ ☀ ☆ ☂ ☻ ♞ ☯ ☭ ☢ € → ~`!@#$%^&*()_+-=[]\|:;"'<>?,./ 1 ❤ ☀ ☆ ☂ ☻ ♞ ☯ ☭ ☢ € → ~`!@#$%^&*()_+-=[]\|:;"'<>?,./ 2 ❤ ☀ ☆ ☂ ☻ ♞ ☯ ☭ ☢ € → ~`!@#$%^&*()_+-=[]\|:;"'<>?,./def l2 ❤ ☀ ☆ ☂ ☻ ♞ ☯ ☭ ☢ € → ~`!@#$%^&*()_+-=[]\|:;"'<>?,./ 1 ❤ ☀ ☆ ☂ ☻ ♞ ☯ ☭ ☢ € → ~`!@#$%^&*()_+-=[]\|:;"'<>?,./ 2 ❤ ☀ ☆ ☂ ☻ ♞ ☯ ☭ ☢ € → ~`!@#$%^&*()_+-=[]\|:;"'<>?,./"
122434 *()_+-=[]\|:;"'<>?,./def l2 ❤ ☀ ☆ ☂ ☻ ♞ ☯ ☭ ☢ € → ~`!@#$%^&*()_+-=[]\|:;"'<>?,./ 1 ❤ ☀ ☆ ☂ ☻ ♞ ☯ ☭ ☢ € → ~`!@#$%^&*()_+-=[]\|:;"'<>?,./ 2 ❤ ☀ ☆ ☂ ☻ ♞ ☯ ☭ ☢ € → ~`!@#$%^&*()_+-=[]\|:;"'<>?,./"
I use datatbles.js and there when populating cells i have a function that returns an html string
return '<span title="TEXT"></span>'
When i do this
return '<span title="'+text+'"></span>'
Or this
return '<span title="'+JSON.stringify(text)+'"></span>'
It breaks my returned element.
How could I approach inserting the text above with new lines etc. to the title
attribute so it would work properly?
Thank you!
javascript json string datatable datatables
How does it 'break'? Does the ' character break it?
– L0uis
Mar 8 at 22:33
1
There are things like single and double quotes, square, curly, and angle brackets, and other such symbols and punctuation that can be interpreted as HTML markers instead of plain text. You will need to escape those characters according to this spec.
– Abion47
Mar 8 at 22:34
@Abion47 Thanks, it helped!
– Мария
Mar 10 at 23:16
add a comment |
i have the following text (with new lines).
"☢☢☢☢2222def l2 ❤ ☀ ☆ ☂ ☻ ♞ ☯ ☭ ☢ € → ~`!@#$%^&*()_+-=[]\|:;"'<>?,./ 1 ❤ ☀ ☆ ☂ ☻ ♞ ☯ ☭ ☢ € → ~`!@#$%^&*()_+-=[]\|:;"'<>?,./ 2 ❤ ☀ ☆ ☂ ☻ ♞ ☯ ☭ ☢ € → ~`!@#$%^&*()_+-=[]\|:;"'<>?,./def l2 ❤ ☀ ☆ ☂ ☻ ♞ ☯ ☭ ☢ € → ~`!@#$%^&*()_+-=[]\|:;"'<>?,./ 1 ❤ ☀ ☆ ☂ ☻ ♞ ☯ ☭ ☢ € → ~`!@#$%^&*()_+-=[]\|:;"'<>?,./ 2 ❤ ☀ ☆ ☂ ☻ ♞ ☯ ☭ ☢ € → ~`!@#$%^&*()_+-=[]\|:;"'<>?,./"
122434 *()_+-=[]\|:;"'<>?,./def l2 ❤ ☀ ☆ ☂ ☻ ♞ ☯ ☭ ☢ € → ~`!@#$%^&*()_+-=[]\|:;"'<>?,./ 1 ❤ ☀ ☆ ☂ ☻ ♞ ☯ ☭ ☢ € → ~`!@#$%^&*()_+-=[]\|:;"'<>?,./ 2 ❤ ☀ ☆ ☂ ☻ ♞ ☯ ☭ ☢ € → ~`!@#$%^&*()_+-=[]\|:;"'<>?,./"
I use datatbles.js and there when populating cells i have a function that returns an html string
return '<span title="TEXT"></span>'
When i do this
return '<span title="'+text+'"></span>'
Or this
return '<span title="'+JSON.stringify(text)+'"></span>'
It breaks my returned element.
How could I approach inserting the text above with new lines etc. to the title
attribute so it would work properly?
Thank you!
javascript json string datatable datatables
i have the following text (with new lines).
"☢☢☢☢2222def l2 ❤ ☀ ☆ ☂ ☻ ♞ ☯ ☭ ☢ € → ~`!@#$%^&*()_+-=[]\|:;"'<>?,./ 1 ❤ ☀ ☆ ☂ ☻ ♞ ☯ ☭ ☢ € → ~`!@#$%^&*()_+-=[]\|:;"'<>?,./ 2 ❤ ☀ ☆ ☂ ☻ ♞ ☯ ☭ ☢ € → ~`!@#$%^&*()_+-=[]\|:;"'<>?,./def l2 ❤ ☀ ☆ ☂ ☻ ♞ ☯ ☭ ☢ € → ~`!@#$%^&*()_+-=[]\|:;"'<>?,./ 1 ❤ ☀ ☆ ☂ ☻ ♞ ☯ ☭ ☢ € → ~`!@#$%^&*()_+-=[]\|:;"'<>?,./ 2 ❤ ☀ ☆ ☂ ☻ ♞ ☯ ☭ ☢ € → ~`!@#$%^&*()_+-=[]\|:;"'<>?,./"
122434 *()_+-=[]\|:;"'<>?,./def l2 ❤ ☀ ☆ ☂ ☻ ♞ ☯ ☭ ☢ € → ~`!@#$%^&*()_+-=[]\|:;"'<>?,./ 1 ❤ ☀ ☆ ☂ ☻ ♞ ☯ ☭ ☢ € → ~`!@#$%^&*()_+-=[]\|:;"'<>?,./ 2 ❤ ☀ ☆ ☂ ☻ ♞ ☯ ☭ ☢ € → ~`!@#$%^&*()_+-=[]\|:;"'<>?,./"
I use datatbles.js and there when populating cells i have a function that returns an html string
return '<span title="TEXT"></span>'
When i do this
return '<span title="'+text+'"></span>'
Or this
return '<span title="'+JSON.stringify(text)+'"></span>'
It breaks my returned element.
How could I approach inserting the text above with new lines etc. to the title
attribute so it would work properly?
Thank you!
javascript json string datatable datatables
javascript json string datatable datatables
asked Mar 8 at 22:31
МарияМария
555
555
How does it 'break'? Does the ' character break it?
– L0uis
Mar 8 at 22:33
1
There are things like single and double quotes, square, curly, and angle brackets, and other such symbols and punctuation that can be interpreted as HTML markers instead of plain text. You will need to escape those characters according to this spec.
– Abion47
Mar 8 at 22:34
@Abion47 Thanks, it helped!
– Мария
Mar 10 at 23:16
add a comment |
How does it 'break'? Does the ' character break it?
– L0uis
Mar 8 at 22:33
1
There are things like single and double quotes, square, curly, and angle brackets, and other such symbols and punctuation that can be interpreted as HTML markers instead of plain text. You will need to escape those characters according to this spec.
– Abion47
Mar 8 at 22:34
@Abion47 Thanks, it helped!
– Мария
Mar 10 at 23:16
How does it 'break'? Does the ' character break it?
– L0uis
Mar 8 at 22:33
How does it 'break'? Does the ' character break it?
– L0uis
Mar 8 at 22:33
1
1
There are things like single and double quotes, square, curly, and angle brackets, and other such symbols and punctuation that can be interpreted as HTML markers instead of plain text. You will need to escape those characters according to this spec.
– Abion47
Mar 8 at 22:34
There are things like single and double quotes, square, curly, and angle brackets, and other such symbols and punctuation that can be interpreted as HTML markers instead of plain text. You will need to escape those characters according to this spec.
– Abion47
Mar 8 at 22:34
@Abion47 Thanks, it helped!
– Мария
Mar 10 at 23:16
@Abion47 Thanks, it helped!
– Мария
Mar 10 at 23:16
add a comment |
1 Answer
1
active
oldest
votes
If you do string concatenation you have to worry about all the details of encoding in HTML. Instead of passing HTML strings around, create DOM elements with JavaScript functions:
var span = document.createElement("span");
span.innerText = text;
return span;
The caller should then use appendChild()
to append this element where it's needed, rather than assigning it to innerHTML
.
That would just end up in columns containing the text[object HTMLSpanElement]
– davidkonrad
Mar 10 at 11:27
You don't put the return value ininnerHTML
, you useappendChild
to append it as a DOM element.
– Barmar
Mar 10 at 11:39
I understand your point but DataTables expect a string (treats values from the render callback as strings) ...You could usereturn span.outerHTML
but that seem to ruin markup within data / text (i.e if text is<p>something</p>
)
– davidkonrad
Mar 10 at 13:55
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55071915%2fproper-handling-text-that-was-sent-via-json-when-returning-html-string-and-inser%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
If you do string concatenation you have to worry about all the details of encoding in HTML. Instead of passing HTML strings around, create DOM elements with JavaScript functions:
var span = document.createElement("span");
span.innerText = text;
return span;
The caller should then use appendChild()
to append this element where it's needed, rather than assigning it to innerHTML
.
That would just end up in columns containing the text[object HTMLSpanElement]
– davidkonrad
Mar 10 at 11:27
You don't put the return value ininnerHTML
, you useappendChild
to append it as a DOM element.
– Barmar
Mar 10 at 11:39
I understand your point but DataTables expect a string (treats values from the render callback as strings) ...You could usereturn span.outerHTML
but that seem to ruin markup within data / text (i.e if text is<p>something</p>
)
– davidkonrad
Mar 10 at 13:55
add a comment |
If you do string concatenation you have to worry about all the details of encoding in HTML. Instead of passing HTML strings around, create DOM elements with JavaScript functions:
var span = document.createElement("span");
span.innerText = text;
return span;
The caller should then use appendChild()
to append this element where it's needed, rather than assigning it to innerHTML
.
That would just end up in columns containing the text[object HTMLSpanElement]
– davidkonrad
Mar 10 at 11:27
You don't put the return value ininnerHTML
, you useappendChild
to append it as a DOM element.
– Barmar
Mar 10 at 11:39
I understand your point but DataTables expect a string (treats values from the render callback as strings) ...You could usereturn span.outerHTML
but that seem to ruin markup within data / text (i.e if text is<p>something</p>
)
– davidkonrad
Mar 10 at 13:55
add a comment |
If you do string concatenation you have to worry about all the details of encoding in HTML. Instead of passing HTML strings around, create DOM elements with JavaScript functions:
var span = document.createElement("span");
span.innerText = text;
return span;
The caller should then use appendChild()
to append this element where it's needed, rather than assigning it to innerHTML
.
If you do string concatenation you have to worry about all the details of encoding in HTML. Instead of passing HTML strings around, create DOM elements with JavaScript functions:
var span = document.createElement("span");
span.innerText = text;
return span;
The caller should then use appendChild()
to append this element where it's needed, rather than assigning it to innerHTML
.
edited Mar 10 at 11:40
answered Mar 8 at 23:37
BarmarBarmar
434k36260363
434k36260363
That would just end up in columns containing the text[object HTMLSpanElement]
– davidkonrad
Mar 10 at 11:27
You don't put the return value ininnerHTML
, you useappendChild
to append it as a DOM element.
– Barmar
Mar 10 at 11:39
I understand your point but DataTables expect a string (treats values from the render callback as strings) ...You could usereturn span.outerHTML
but that seem to ruin markup within data / text (i.e if text is<p>something</p>
)
– davidkonrad
Mar 10 at 13:55
add a comment |
That would just end up in columns containing the text[object HTMLSpanElement]
– davidkonrad
Mar 10 at 11:27
You don't put the return value ininnerHTML
, you useappendChild
to append it as a DOM element.
– Barmar
Mar 10 at 11:39
I understand your point but DataTables expect a string (treats values from the render callback as strings) ...You could usereturn span.outerHTML
but that seem to ruin markup within data / text (i.e if text is<p>something</p>
)
– davidkonrad
Mar 10 at 13:55
That would just end up in columns containing the text
[object HTMLSpanElement]
– davidkonrad
Mar 10 at 11:27
That would just end up in columns containing the text
[object HTMLSpanElement]
– davidkonrad
Mar 10 at 11:27
You don't put the return value in
innerHTML
, you use appendChild
to append it as a DOM element.– Barmar
Mar 10 at 11:39
You don't put the return value in
innerHTML
, you use appendChild
to append it as a DOM element.– Barmar
Mar 10 at 11:39
I understand your point but DataTables expect a string (treats values from the render callback as strings) ...You could use
return span.outerHTML
but that seem to ruin markup within data / text (i.e if text is <p>something</p>
)– davidkonrad
Mar 10 at 13:55
I understand your point but DataTables expect a string (treats values from the render callback as strings) ...You could use
return span.outerHTML
but that seem to ruin markup within data / text (i.e if text is <p>something</p>
)– davidkonrad
Mar 10 at 13:55
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55071915%2fproper-handling-text-that-was-sent-via-json-when-returning-html-string-and-inser%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
How does it 'break'? Does the ' character break it?
– L0uis
Mar 8 at 22:33
1
There are things like single and double quotes, square, curly, and angle brackets, and other such symbols and punctuation that can be interpreted as HTML markers instead of plain text. You will need to escape those characters according to this spec.
– Abion47
Mar 8 at 22:34
@Abion47 Thanks, it helped!
– Мария
Mar 10 at 23:16