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
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?