[CKEditor] CKEditor Add parameter for Link URL

Forge Component
(29)
Published on 26 May by Prasad Rao
29 votes
Published on 26 May by Prasad Rao

Is there a way I can pass a value to CKEditor and set as value as default, using this input parameter?

If I click on the Link icon, I need to pass the parameter to CKEditor, how can I do it?


Hi,

Can you please explain little bit more what you are trying to do? you can enter a text, select and click the anchor button will give you the display text but if you want the default without user entering something then check https://ckeditor.com/docs/ckeditor4/latest/guide/dev_howtos_dialog_windows.html, the link actually have an example of how you set the default value for URL.

Regards.

Prasad Rao wrote:

Hi,

Can you please explain little bit more what you are trying to do? you can enter a text, select and click the anchor button will give you the display text but if you want the default without user entering something then check https://ckeditor.com/docs/ckeditor4/latest/guide/dev_howtos_dialog_windows.html, the link actually have an example of how you set the default value for URL.

Regards.


What I am trying to do is by clicking on the link icon as previous image shows, I want to pass the URL as parameter to CKEditor. The point is to have as the bellow image shows to pass an input parameter in order to have the default url input defined.


Solution

Hi,

I just added below script after the ckeditor web block and get the default value as www.example.com in url

"
<script>
var waitCKEDITOR = setInterval(function() {
    if (window.CKEDITOR) {
       clearInterval(waitCKEDITOR);
       CKEDITOR.on( 'dialogDefinition', function( ev ) {
            // Take the dialog name and its definition from the event data.
            var dialogName = ev.data.name;
            var dialogDefinition = ev.data.definition;

            // Check if the definition is from the dialog window you are interested in (the 'Link' dialog window).
            if ( dialogName == 'link' ) {
                // Get a reference to the 'Link Info' tab.
                var infoTab = dialogDefinition.getContents( 'info' );

                // Set the default value for the URL field.
                var urlField = infoTab.get( 'url' );
                urlField[ 'default' ] = 'www.example.com';
            }
        });
    }
}, 1000);
</script>
"


Output:

Regards.

Solution