tinymce图像插入,第二次工作,但不是第一次

tinymce image insert, works second time but not the first

本文关键字:第一次 第二次 图像 插入 tinymce 工作      更新时间:2023-09-26

我正在使用CakePHP和一个自定义文件浏览器,以及TinyMCE。

这是我的回拨:

<script type="text/javascript">
function fileBrowserCallBack(field_name, url, type, win) { 
            browserField = field_name; 
            browserWin = win; 
            window.open('/controller/mupload', 'browserWindow', 'modal,width=600,height=500,scrollbars=yes');
        }

tinyMCE.init({ 
            mode : 'textareas', 
            theme : 'advanced', 
            // theme specific stuff
            file_browser_callback: 'fileBrowserCallBack', 
            width: '620', 
            height: '380', 
            relative_urls : false 
        });
</script> 

回调中的window.open引用了CakePHP中的上传脚本。这样可以上传并完美地显示图像。当我选择一个图像时,图像的路径显示在TinyMCE的Image URL字段中,所有这些看起来都像在工作。

然后我点击Insert,TinyMCE添加了这个HTML:

<p><img border="0" /></p>-完全忽略图像的路径-即使已设置。

如果我点击"插入图像",浏览到另一个(或相同的)图像,然后选择插入,图像会完美显示,路径正确,正如你所期望的那样。

我可以提供更多的代码,但不幸的是,没有实时链接。

总之,当我第一次尝试插入图像时,它插入了一个无效的标签。第二次,它工作得很好。

Firebug没有显示错误。

有什么建议吗?

TinyMCE版本:

majorVersion:"3",
minorVersion:"4.2",
releaseDate:"2011-04-07"

谢谢。

这应该在他们的罚单中得到了回答:http://tinymce.moxiecode.com/develop/bugtracker_view.php?id=4427

但据报道:http://tinymce.moxiecode.com/develop/bugtracker_view.php?id=4499

中的一些修复程序http://tinymce.moxiecode.com/forum/viewtopic.php?id=25646

我通过将convert_urls配置设置为false来修复此问题。

有关该配置和相关配置的更多信息,请参阅此处:https://www.tiny.cloud/docs/configure/url-handling/#qhowdoiconvertmyurlstorelativeabsoluteorabsolutewithdomain

convert_urls

This option enables you to control whether TinyMCE is to be smart and restore URLs to their original values. URLs are automatically converted (messed up) by default because the browser’s built-in logic works this way. There is no way to get the real URL unless you store it away. If you set this option to false it tries to keep these URLs intact. This option is set to true by default, which means URLs are forced to be either absolute or relative depending on the state of relative_urls.
Type: Boolean
Default Value: true

相对URL对于与包含TinyMCE编辑器的页面具有相同域的URL。如果设置为:

true — All URLs created in TinyMCE will be converted to a link relative to the document_base_url.
false — All URLs will be converted to absolute URLs.
Type: Boolean
Default Value: true

document_base_url

This option specifies the base URL for all relative URLs in the document. The default value is the directory of the current document. If a value is provided, it must specify a directory (not a document) and must end with a /.
This option also interacts with the relative_urls, remove_script_host, and convert_urls options to determine whether TinyMCE returns relative or absolute URLs. The FAQ contains a thorough description and examples of working with relative and absolute URLs.
Type: String
相关文章: