Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
187
rated 0 times [  191] [ 4]  / answers: 1 / hits: 22761  / 12 Years ago, wed, august 29, 2012, 12:00:00

I need to make this into a string in java:



 <script type=text/javascript>document.write(<img src=UpArrow.png /> ); </script>


Can someone help? I keep trying and it ends up like this...



return <script type=text/javascript>document.write(<img src=UpArrow.png /> ); </script>;


Which doesn't work because I need to double escape the quotes before and after UpArrow.png. since it needs to be escaped in javascript and not in java.



.



.



2019 Update: If you are looking at this, god help your soul. This is awful code and if you're trying to do things this way you're doing it wrong (As others suggested to me).



The correct way to do this would be jquery or one of the zillion DOM-modifying frameworks that exist now and popping stuff into / out of the scope of the DOM.



If you are doing this, you should not look at the code above or the solutions below, but should instead go learn more, as this is a path to make spaghetti code.


More From » java

 Answers
89

Apache commons have a methods just for this in StringEscapeUtils : the escapeJavaScript method.


[#83348] Tuesday, August 28, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
desiraeleandrah

Total Points: 202
Total Questions: 111
Total Answers: 115

Location: Macau
Member since Mon, Nov 16, 2020
4 Years ago
desiraeleandrah questions
Thu, Nov 19, 20, 00:00, 4 Years ago
Wed, Nov 11, 20, 00:00, 4 Years ago
Wed, Oct 14, 20, 00:00, 4 Years ago
;