javascript - 如何在显示弹出窗口之前解码特定元素中的 html?

标签 javascript smarty popupwindow

我在 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/

相关文章:

javascript - 增加并发 HTTP 调用

php - jquery 搜索和替换

php - Smarty 修改器的多个参数

javascript - 尝试修改此 JavaScript 代码以减小弹出窗口的大小或在用户单击框外时关闭

javascript - 使用 window.open() 方法在打印预览页面中添加 javascript

javascript - 如何使用 javascript 制作带有复选框的弹出窗口?

javascript - 在多个点之间绘制扇形多边形

javascript - 尝试从外部 JS 文件调用函数

javascript - 是否可以在页面其他部分加载后克隆图像而不加载?

smarty - 我应该将Smarty模板引擎与Yii这样的MVC一起使用吗?