1. 程式人生 > >關於富文字kindeditor中上傳本地圖片成功後獲取到的圖片路徑是相對路徑修改為絕對路徑

關於富文字kindeditor中上傳本地圖片成功後獲取到的圖片路徑是相對路徑修改為絕對路徑

找到kindeditor外掛kindeditor-all.js有的或者是kindeditor.js,找到urltype的設定,

K.options = {     designMode : true,     fullscreenMode : false,     filterMode : true,     wellFormatMode : true
,     shadowMode : true,     loadStyleMode : true,     basePath : K.basePath,     themesPath : K.basePath + 'themes/',     langPath : K.basePath +
'lang/',     pluginsPath : K.basePath + 'plugins/',     themeType : 'default',     langType : 'zh-CN',     urlType : 'absolute',     newlineTag : 'p'
,

可以改為absolute。然後全域性搜尋absolute,找到下面一行程式碼:

     if (mode === 'relative') {         url = getRelativePath(host + pathname, 0). substr( 2);     } else if (mode === 'absolute') {          // if (url.substr(0, host.length) === host) {          //  url = url.substr(host.length);          // }     }      return url;
if (url.substr(0, host.length) === host) {        url = url.substr(host.length);   }這行程式碼會把上傳的檔案路徑前面的域名埠都剪掉了,所以我們嘗試將他們註釋或者刪除。就會拿到絕對路徑。