du5739 2012-12-04 08:47
浏览 35
已采纳

将JavaScript显示为文件中的可编辑代码

I am working to make html files of a website editable using CKEditor. I want the user should be able to edit the code of any html file via the admin panel. For this purpose I am using the file_get_contents function which seems to work fine except the JavaScript code is not displayed as editable code in the editor. I have tried the fread function as well and it also displays all the contents of the file in editor but I am still unable to get the JavaScript code in the editor as editable code. Any help?

Here's the code:

$contents = file_get_contents($_REQUEST['path']);
if(!$contents) die("Page not found");      
    $oFCKeditor = new FCKeditor('content') ;
    $oFCKeditor->BasePath = 'fckeditor/' ;
    $oFCKeditor->Width = '100%' ;
    $oFCKeditor->Height = '350' ; 
    if($mode == 'edit')$oFCKeditor->Value = stripslashes($contents);
    $oFCKeditor->Create() ; 
  • 写回答

1条回答 默认 最新

  • dpe77294 2012-12-04 09:09
    关注

    CKEditor (formerly FCKeditor) is a WYSIWYG(What-You-See-Is-What-You-Get) editor. WYSIWYG Editors take all the html,css & javascript, execute/parse it & try to display the output. so that's the reson Javascript code is not being shown in editor, as the editor is build to parse the javascript & display its output; instead of actual code.

    Now, If you want to work directly with code, than its output. there are two options:

    1. Use the "View Source" button & you should be able to see all the javascript along with other code.There won't be any syntax highlighting but I this would work fine for small edits
    2. Use Source code editor: If you want proper syntax highlighting, you have to switch to a source code editor instead of WYSIWYG(What-You-See-Is-What-You-Get) editor. example of some source code editor
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 materialstudio计算氢键脚本问题
  • ¥15 配置FPT报错,该如何处理
  • ¥15 请大家看一下这个代码咋写,一点思路都没有,最好能做一下,不要伪代码,有偿
  • ¥15 有偿请人帮写个安卓系统下禁止装软件及禁止拷入文件的程序
  • ¥100 用 H.265 对音视频硬编码 (CUDA)
  • ¥20 mpich安装完成后出问题
  • ¥15 stm32循迹小车代码问题
  • ¥15 输入一堆单词,使其去重输出
  • ¥15 qc代码,修改和添加东西
  • ¥50 Unity的粒子系统使用shadergraph(内置管线)制作的一个顶点偏移shader,但是粒子模型移动时,顶点也会偏移