duankangpazhuo0347 2011-03-07 21:42
浏览 54
已采纳

ck编辑器 - 服务器预览?

How would I go about getting ckeditor's preview button to send the content to the server so I can show it in a custom page when preview is clicked?

  • 写回答

2条回答 默认 最新

  • dongwen9947 2011-09-04 00:24
    关注

    We're doing something like this except that we have a preview link on the page that loads the editor. The approach could be used for a button within the editor, but it requires additional coding (I'll outline that approach at the bottom).

    The preview link looks something like this:

    <a href="#" onclick="return doPreview();">Preview the page</a>
    

    We have the doPreview function:

    function doPreview() {
    var hiddenForm = document.forms[ 'hidden_form' ];
    
    // TextareaId is the id of the textarea being replaced with CKEditor (the instance name)
    hiddenForm.elements[ 'preview_content' ].value = CKEDITOR.instances.TextareaId.getData();
    
    // "myform" is the active form that contains the textarea replaced by CKEditor.
    var liveForm = document.forms[ 'myform' ];
    if ( ! liveForm ) {
      alert( 'Error finding "myform" form.' );
      return false;
    }
    
    hiddenForm.submit();
    
    return true;
    

    }

    Finally, there's a form with hidden fields (hiddenForm):

    <form name="hiddenForm" action="HTTP://www.yoursite.com/preview_template" method="POST" target="_blank">
      <input type="hidden" name="preview_content" value="" />
    </form>
    

    So, the link is clicked and the doPreview function is called.
    The function grabs the content from CKEditor and assigns it to a hidden field in the hidden form.
    Then the function submits the hidden form.
    The hidden form is posted and the preview template is loaded in a new window.
    The content area of the preview template is populated with $_POST['preview_content'] (the content data from the editor).

    You can modify to contain any variables you need to post.


    To do this by clicking a button within CKEditor:
    You could create a custom plugin. There's a tutorial section with easy instructions for creating a plugin here:
    http://docs.cksource.com/CKEditor_3.x/Tutorials

    The plugin could work with a hidden form on the main page again, you'll need to call the parent window from your plugin function.

    Or, you could compose the form with JavaScript within your plugin and submit it from there.

    Note: You can disable the default preview functionality using this setting:

    config.removePlugins = 'preview';
    

    Be Well, Joe

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器