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

时间:2011-06-09 20:47:52

标签: javascript cakephp callback tinymce

我正在使用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"

谢谢。

2 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

我通过将 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

relative_urls 对于与包含 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