我在 smarty 代码中有以下两个 JavaScript 函数,我想用它们显示一个包含 html 标记的动态内容的弹出窗口:
第一个打开弹出窗口的函数:
<script type="text/javascript">
// global variable for subwindow reference
var newWindow;
// generate and fill the new window
{literal}
function makeNewWindow( ) {
// make sure it isn't already opened
if (!newWindow || newWindow.closed) {
newWindow = window.open("", "prd_window", "height=400, width=300, fullscreen, resizable");
// delay writing until window exists in IE/Windows
setTimeout("writeToWindow( )", 50);
} else if (newWindow.focus) {
// window is already open and focusable, so bring it to the front
newWindow.focus( );
}
}
{/literal}
用于将动态内容写入弹出窗口的第二个函数,从第一个函数调用:
function writeToWindow( ) {ldelim}
// assemble content for new window
var newContent = "<html><head><title>title text here</title></head>";
newContent += "<body>";
var full_descr = "{$markup_info.fulldescr|strip|escape:'html'}";
newContent += "<div id=\"div_fulldescr\">" + full_descr + "</div>";
newContent += "</body></html>";
// write HTML to new window document
newWindow.document.write(newContent);
newWindow.document.close( ); // close layout stream
{rdelim}
</script>
在第二个函数中,我使用“escape”smarty 修饰符对 full_descr 变量中包含的 html 标记进行编码,因此 JavaScript 代码不会中断。 $markup_info 是一个智能关联数组,fulldescr 是它的索引之一。
上面的代码弹出一个窗口,其中 div_fulldescr 元素的内容显示为 html 标记,正如预期的那样,即它尚未被解码。 我想知道在显示弹出窗口之前如何解码 div_fulldescr div 元素的 html 标记。
最佳答案
您可能需要将 {$markup_info.fulldescr|strip|escape:'html'}
替换为 {$markup_info.fulldescr|escape:'javascript'}
。
关于javascript - 如何在显示弹出窗口之前解码特定元素中的 html?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8929021/