打开 jquery 模式对话框后,Iframe 内容会丢失

Iframe contents are lost after opening a jquery modal dialog

本文关键字:Iframe jquery 模式 对话框 打开      更新时间:2023-09-26

我有一个iframe。它在一个模态内。请参阅下面的代码:

<iframe id="edit-text-modal-value_ifr" src='javascript:""' frameborder="0" allowtransparency="true" title="Rich Text AreaPress ALT-F10 for toolbar. Press ALT-0 for help" style="width: 100%; height: 100px; display: block;">
   #document
   <!DOCTYPE>
   <html>
        <head xmlns="http://www.w3.org/1999/xhtml">
           <style id="mceDefaultStyles" type="text/css">
               .mceResizeHandle {
                   position: absolute;
                   border: 1px solid black;
                   background: #FFF;
                   width: 5px;
                   height: 5px;
                   z-index: 10000
               }
               .mceResizeHandle:hover {
                   background: #000
               }
               img[data-mce-selected] {
                   outline: 1px solid black
               }
               img.mceClonedResizable,
               table.mceClonedResizable {
                   position: absolute;
                   outline: 1px dashed black;
                   opacity: .5;
                   z-index: 10000
               }
           </style>
           <base href="http://localhost/drupal-7.34/">
           <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
           <link type="text/css" rel="stylesheet" href="http://localhost/drupal-7.34/sites/all/libraries/tinymce/jscripts/tiny_mce/themes/advanced/skins/default/content.css">
           <link type="text/css" rel="stylesheet" href="http://localhost/drupal-7.34/themes/bartik/css/layout.css">
           <link type="text/css" rel="stylesheet" href="http://localhost/drupal-7.34/themes/bartik/css/style.css">
           <link type="text/css" rel="stylesheet" href="http://localhost/drupal-7.34/themes/bartik/css/colors.css">
       </head>
       <body id="tinymce" class="mceContentBody " onload="window.parent.tinyMCE.get('edit-text-modal-value').onLoad.dispatch();" contenteditable="true" spellcheck="false" dir="ltr">
           <p>
               <br data-mce-bogus="1">
           </p>
       </body>  
   </html>
</iframe>

当我使用 jquery 模态插件打开另一个模态时,iframe 的内容丢失了。为什么?我将如何预防它?

Jquery Code:

jQuery('#myid_templates_editor_insertf_field_modal').dialog('open');    

我的新 Iframe 代码:

<iframe id="edit-text-modal-value_ifr" src='javascript:""' frameborder="0" allowtransparency="true" title="Rich Text AreaPress ALT-F10 for toolbar. Press ALT-0 for help" style="width: 100%; height: 100px; display: block;">
    #document
    <html>
        <head></head>
        <body></body>
    </html>
</iframe>
<script type="text/javascript"> 
    $('.the-modal').bind('shown', function() {
       tinyMCE.execCommand('mceAddControl', false, 'mce-<?=$reply["id"]?>');
    });
    $('.the-modal').bind('hide', function() {
        tinyMCE.execCommand('mceRemoveControl', false, 'mce-<?=$reply["id"]?>');
    });
</script>

这是一个错误,我在这里找到了解决方案。

当然会消失。因为模态数据是在调用另一种模式时可以执行的操作 dynimacally.so 创建的 将 iframe 对象复制到另一个类似对象

var tmp=document.getelememntbyid('iframeid');

并全局声明 tmp 变量,并在需要时再次使用它。