yii2:change FCKConfig.DefaultLinkTarget to "_blank" in ckeditor

192 Views Asked by At

i want change default target to _blank in create link


'DefaultLinkTarget' => '_blank',


how to can do this !

   <?php

use dosamigos\ckeditor\CKEditor;

?>

 <?=
    $form->field($model, 'summary')->widget(CKEditor::className(), [
        'options' => ['rows' => 1],
        'clientOptions' => [
            'language' => 'fa',
//            'DefaultLinkTarget' => '_blank',
            'height' => '200'
        ],
        'preset' => 'full',
    ])
    ?>
2

There are 2 best solutions below

0
ScaisEdge On

you could use the options target

  <?=
      $form->field($model, 'summary')->widget(CKEditor::className(), [
          'options' => ['rows' => 1, 'target' =>'_blank'],
          'clientOptions' => [
              'language' => 'fa',
  //            'DefaultLinkTarget' => '_blank',
              'height' => '200'
          ],
          'preset' => 'full',
      ])
      ?>

or try add a script in your page

<script> 
 // Sets the default config value to _blank.
 CKEDITOR.config.DefaultLinkTarget = '_blank';
</script>
0
j.swiderski On

I'm not sure if you are talking about CKEditor or FCKeditor but in CKEditor there is no such config setting. You need to use dialogDefinition event for that. The code would be:

<script> 
var editor = CKEDITOR.replace( 'editor1', { });

CKEDITOR.on( 'dialogDefinition', function( ev ) {
    var dialogDefinition = ev.data.definition;
    if ( ev.data.name == 'link' ){
        dialogDefinition.getContents( 'target' ).get( 'linkTargetType' )['default'] = '_blank';
    }
});
</script>