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

报告相同问题?

悬赏问题

  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了
  • ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统
  • ¥188 需要修改一个工具,懂得汇编的人来。
  • ¥15 livecharts wpf piechart 属性
  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题