I’m sending some HTML code back to an iframe using a java servlet and an iframe on the js side. I’m actually just parsing some json from the HTML code by encasing it in a single <div>, using jQuery, but the string that gets sent back sometimes has added text.
If the text that gets added has a word with enclosing angle brackets, Firefox will automatically close the brackets for me, which I don’t want.
For example, if I send this:
<div>{"location":[],"columns":["<case expression>","headers"]}</div>
Firefox (and ONLY Firefox so far, not IE or chrome) will receive it as this:
<div>{"location":[],"columns":["<case expression>","headers"]}</case></div>
which screws up my parsing. I’m sending the text with the Content-Type of text/html, which I think might be causing the issue. I’ve tried Content-Type of application/json, but it won’t write html to the iframe unless I’m using the text/html.
Can someone help me with a solution? I’m willing to try a different method of sending the data if it’s not too extensive.
In order to keep the browser from interpreting HTML meta-characters as such, so that your “<” and “>” characters end up as part of the text, you can “escape” them as HTML entities. The “<” character is
<and the “>” is>. People generally also quote the ampersand (“&”) as&but I think browsers are generally a little smarter about that.Edit by OP for code solution:
I used
StringEscapeUtils.escapeHTML(), which worked perfectly. Thanks!