Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/447.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript CKEditor-使链接可单击(在只读模式下)_Javascript_Html_Ckeditor - Fatal编程技术网

Javascript CKEditor-使链接可单击(在只读模式下)

Javascript CKEditor-使链接可单击(在只读模式下),javascript,html,ckeditor,Javascript,Html,Ckeditor,我使用的是CKEditor 4.5.4,我有一个按钮,可以使用以下命令切换编辑器的只读状态: var editor = CKEDITOR.replace( 'text', { height: '200px' }); editor.setReadOnly(false); 我要做的是,当编辑器处于只读模式时,使CKEditor内的所有链接都可单击-当只读为false时,我希望链接正常运行 目前,我正在努力使链接可点击-检查它们,我可以看到它们是有效的HTML(在某一点上,我认为CK编辑器中的链接只

我使用的是CKEditor 4.5.4,我有一个按钮,可以使用以下命令切换编辑器的只读状态:

var editor = CKEDITOR.replace( 'text', { height: '200px' });
editor.setReadOnly(false);
我要做的是,当编辑器处于
只读
模式时,使CKEditor内的所有链接都可单击-当
只读
为false时,我希望链接正常运行


目前,我正在努力使链接可点击-检查它们,我可以看到它们是有效的HTML(在某一点上,我认为CK编辑器中的链接只是带有下划线的蓝色文本)-我假设CKEditor正在阻止这些链接的默认操作。这是可以切换的吗?

这是故意的行为,因为打开链接会导致一些问题。下面是代码的一部分

另请参见和,了解此行为引起的更广泛背景和问题


您可以添加自己的链接处理程序,如:

var editor = CKEDITOR.replace( 'editor1', { readOnly: true } );

editor.on( 'contentDom', function() {
    var editable = editor.editable();
    editable.attachListener( editable, 'click', function( evt ) {
        var link = new CKEDITOR.dom.elementPath( evt.data.getTarget(), this ).contains( 'a' );
        if ( link && evt.data.$.button != 2 && link.isReadOnly() ) {
            window.open( link.getAttribute( 'href' ) );
        }
    }, null, null, 15 );
} );
与HTML类似:

<textarea name="editor1" id="editor1" rows="10" cols="80">  
    <p>Foo Bar Baz <a href="http://ckeditor.com">CKEditor</a></p>
</textarea>

福吧巴兹酒店

请查看以测试它。您还可以添加其他检查,查看
href
是否为空,等等


这并不是一个完美的解决方案,因为理想情况下,我们希望浏览器能够处理本地打开的点击链接。然而,在大多数情况下,它应该按预期工作。 此外,由于用户能够以任何方式操作链接href(在编辑过程中),这可能会导致一些安全问题