If you try this <script language="javascript"> var win=open("","_blank"); var doc = win.document; doc.open(); doc.write("<a href='http://sohu.net'>sohu</a></p>"); doc.close(); </script>You will know that this string can be written out. But You are going to have problems if the string contains newlines.Here is a suggestion, put the string in a hidden layer, like this <div id="dvHidden" style="display:none"><%=a%></div>Then when you are ready to write, try win.document.write(document.all('dvHidden').innerHTML);Good luck!
如下:
var str = server.htmlEncode("<p><ahref='http://sohu.net'>sohu</a></p>");
document.write(str);
这样字符串中包含的html代码将会原样输出,而不会再被浏览器解释执行。
第一:我现在必须用document.write
第二:我不是不要它执行代码,我是让它执行,但是不知道怎么把源代码给字符串a
然后document.write(a);
这样不行吗?
我用的是jsp编程,我把纯html写在了字符串a里,让后调用javascript把jsp里的字符串a打印出来
document.write(‘《%=a%》’);可是我试了不行,/ “ ...好象都显示不出来了
<script language="javascript">
var win=open("","_blank");
var doc = win.document;
doc.open();
doc.write("<a href='http://sohu.net'>sohu</a></p>");
doc.close();
</script>You will know that this string can be written out. But You are going to have problems if the string contains newlines.Here is a suggestion, put the string in a hidden layer, like this
<div id="dvHidden" style="display:none"><%=a%></div>Then when you are ready to write, try
win.document.write(document.all('dvHidden').innerHTML);Good luck!