简体   繁体   中英

javascript friendly replacement for ' character available?

on my xpage I set a javascript variable onload:

var custName = '#{javascript: matterBean.getMatter().getCustomer().getCustName();}';

this variable I use to replace later the title of a bootstrap dialog.

I notice names with the ' character in it break the code.

I could replace it with

var custName = "#{javascript: matterBean.getMatter().getCustomer().getCustName();}";

but then this would break if the name contains the " character.

Is there an alternative, a javascript friendly replacement so the back-end code (java) could return a javascript friendly replacement for the ' character?

You can use Apache Commons StringEscapeUtils for escaping the string. Example:

StringEscapeUtils.escapeJavaScript(str);
StringEscapeUtils.escapeJavaScript(str);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM