在線客服

    電話①:189 6508 9135(張先生)
    電話②:134 0599 8886(何小姐)
    電話③:0591-83489135

    技術文章


    ASPCMS用百度編輯器JS/html代碼(script標簽)被過濾的解決辦法


    我們用百度編輯器在文章中經常會插入各種代碼,在第一次添加插入代碼后,源碼模式下看起來是正常的,但是為什么保存完之后,數據庫中正常,但是編輯器中不正常呢?那是因為后臺的百度編輯器就會把script標簽給過濾掉,不能完整的顯示。今天我們印秀網絡來教你解決這個問題。

    很多富文本編輯器都有兩種初始化方式,以UEditor為例,一種是textarea標簽,一種是script標簽。

    舉例textarea方式:

    <textarea id="container" name="content">
        這里寫你的初始化內容</textarea><script type="text/javascript" src="ueditor.config.js"></script><script type="text/javascript" src="ueditor.all.js"></script><script type="text/javascript">
        var ue = UE.getEditor('container');</scritp>

    舉例script方式:

    <script id="container" name="content" type="text/plain">
        這里寫你的初始化內容</script><script type="text/javascript" src="ueditor.config.js"></script><script type="text/javascript" src="ueditor.all.js"></script><script type="text/javascript">
        var ue = UE.getEditor('container');</script>

    兩種方式的區(qū)別也只在于容器,我之前一直使用的是textarea方式,因為當時UEditor的script方式有一些小問題。

    在今天尋找過濾問題的解決辦法時,想了很多辦法,看別人的配置文件等,但終究沒解決。在不斷搜索中,打開UEditor之前的幫助文檔,現在官網已經去除了該舊文檔的鏈接,在該文檔中看到了這樣一個問題:

    大部分編輯器的容器都使用textarea,為什么UEditor采用了很特殊的script標簽?

    首先要說明一點的是,UEditor也支持textarea標簽作為編輯器的外圍容器,只要將對應的標簽名字換成textarea即可。除此之外,UEditor還支持使用div和script標簽作為其容器。之所以要這樣做,只是為了盡最大可能去滿足和適應用戶的各種不同需求。官方推薦使用script標簽的原因是textarea會在提交數據的時候自動對里面的部分html文本進行一次特殊字符轉義,從而導致有些不熟悉的用戶在再編輯的時候出現編碼混亂的問題。而使用script標簽可以很好地克服這個缺點。

    官方文檔里面提到了“官方推薦使用script標簽的原因是textarea會在提交數據的時候自動對里面的部分html文本進行一次特殊字符轉義”,看到這句話后豁然開朗,一切問題的根源都在于容器標簽而已,將容器標簽修改為script后,一切都正常了。

    ASPCMS前端代碼顯示不完整解決方案

    1、修改inc/AspCms_CommonFun.asp,代碼728處左右

    Function decodeHtml(Byval str)
    IF len(str)=0 OR Trim(str)="" or isNull(str) then exit function
    str=replace(str,"&apos;",CHR(39))
    str=replace(str,"&#160;"," ")
    decodeHtml=str
    End Function

    添加下面一段新代碼

    Function decodeHtml2(Byval str)
    IF len(str)=0 OR Trim(str)="" or isNull(str) then exit function
    str=replace(str,"&nbsp;"," ")
    str=replace(str,"&quot;",CHR(34))
    decodeHtml2=str
    End Function

    2、修改inc/AspCms_templateFun.asp,代碼624處左右

    添加下面一段新代碼

    content=replacekey(decodeHtml2(rsObj("Content")))

    3、修改aspcms_admin/_content/_Content/AspCms_ContentAdd.asp

    <script id="myEditor" name="Content" type="text/plain"><%=content%></script>
    <script> UE.getEditor('myEditor'); </script>

    4、修改aspcms_admin/_content/_Content/AspCms_ContentEdit.asp

    <script id="myEditor" name="Content" type="text/plain"><%=content%></script>
    <script> UE.getEditor('myEditor'); </script>

    5、修改aspcms_admin/_content/AspCms_ContentFun.asp,代碼237行下添加一段代碼

    Content=decodeHtml2(rs("Content"))

    相關文章

    首頁  電話  咨詢  頂部
    久久精品韩国AV电影,人妻无码在线一区二区,97国产在线,涩涩亚洲中文无码