Javascript 当文本显示在broswer页面上时取消转义的字符
有些内容是从服务器获取的,并显示在浏览器的新页面上。例如,内容是Javascript 当文本显示在broswer页面上时取消转义的字符,javascript,html,escaping,Javascript,Html,Escaping,有些内容是从服务器获取的,并显示在浏览器的新页面上。例如,内容是 "Apple & Orange" 但当它在网页代码中呈现时 function writeConsole(content,idx) { top.consoleRef=window.open('','myconsole' + idx, ',menubar=0' +',toolbar=1' +',status=0' +',scrollbars=1'
"Apple & Orange"
但当它在网页代码中呈现时
function writeConsole(content,idx) {
top.consoleRef=window.open('','myconsole' + idx,
',menubar=0'
+',toolbar=1'
+',status=0'
+',scrollbars=1'
+',resizable=1');
top.consoleRef.document.writeln(
'<html><head><title> Generated Content </title></head>'
+'<body bgcolor=white onLoad="self.focus()">'
+ '<textarea rows="500" cols="500">'
+ content
+ '</textarea>'
+'</body></html>'
);
top.consoleRef.document.close();
}
为什么会这样?我需要显示它所在的字符串。我应该做什么改变来实现这一点?我需要保持那些转义字符的原样。任何帮助或建议都将不胜感激。document.writeln希望其输入为HTML,因此您的内容将被视为HTML,这包括转换实体引用,如
&
或
进入&
和就像一个符咒。Tx:)已添加完整的问题和解决方案->
"Apple & Orange"
top.consoleRef.document.close();
var doc = top.consoleRef.document;
var textarea = doc.getElementsByTagName('textarea')[0];
textarea.value = "Apple & Orange";