cancel
Showing results for 
Search instead for 
Did you mean: 

what if OTR texts in JS contains " ?

daniel_humberg
Contributor
0 Kudos

I have a BSP page that contains the following


<script...>
alert("<%otr(ITSM/mytext)%>");
</script>

I the original language, the text was i.e. "Wrong value in field 'printer'!". But unfortunately, the translators changed the 's to "s in some languages.

Ok, I could tell the translators to use single quotes instead of doubled or to use \", but I don't want to bother them with JS specifics. Is there a better way to assure that an OTR text doesn't contain characters that JS can't handle?

Accepted Solutions (1)

Accepted Solutions (1)

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

Try the following code. It worked for me.

[code]

<%@page language="abap" %>

<%@extension name="htmlb" prefix="htmlb" %>

<%@extension name="phtmlb" prefix="phtmlb" %>

<htmlb:content design="design2003" >

<htmlb:page title="Main page " >

<htmlb:form>

<script>

<%

data: otr_string type string.

otr_string = page->OTR_TRIM( '$TMP/mytext' ).

%>

alert("<%= cl_bsp_utility=>encode_string( in = otr_string encoding = if_bsp_writer=>co_javascript ).%>");

</script>

</htmlb:form>

</htmlb:page>

</htmlb:content>

[/code]

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

You can also use runtime->GET_OTR_TEXT instead of page->otr_trim.

Answers (2)

Answers (2)

Former Member
0 Kudos

Try loading the text into a variable and then manipulating it ???

Just a random thought.

maximilian_schaufler
Active Contributor
0 Kudos

Maybe write yourself a function for your application that wraps around the otr-text include and does javascript-safe character-replacement.