Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7798965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:09:23+00:00 2026-06-02T00:09:23+00:00

There exists an iframe plugin currently built into CKEditor that allows iframes to be

  • 0

There exists an iframe plugin currently built into CKEditor that allows iframes to be inserted into the editor, but displays a rather ugly placeholder no matter what is in the iframe. I am working on a plugin that takes in a video ID from the user and builds an iframe that points to a page for displaying videos on our website. I would like for my users to see a placeholder that makes it clear that they have inserted a video:

Ugly iframe placeholder:
Ugly iframe placeholder

Pretty video placeholder:
Pretty video placeholder

In order to get this far I added this bit of Javascript to my plugin’s onOk function. I’ve included context:

onOk: function () {
    var videoID = this.getValueOf('info', 'video_id');
    var caption = this.getValueOf('info', 'caption');
    var display = this.getValueOf('info', 'display');
    var size = this.getValueOf('info', 'size');
    var width = size * 160;
    var height = size * 120;

    if (videoID.length > 0) {
        if (display == 0) {
            e.insertHtml("<a onclick=window.open(this.href,this.target,'width=" + width + ",height=" + height + "'); return false; target=newVideo href=/kbs/Video.aspx?videoId=" + videoID + "&amp;Width=" + width + "&amp;Height=" + height + ">" + caption + "</a>");
        } else {/*Here is the relevant code that is applied when display is set to embedded*/
            var iframeNode;
            //iframeNode = "<iframe height='" + (height + 40) + "' width='" + (width + 40) + "' src='/kbs/Video.aspx?videoId=1&height=" + height + "&width=" + width + "' frameBorder='0' scrolling='no'></iframe>");
            iframeNode = new CKEDITOR.dom.element('iframe');
            iframeNode.setAttribute('class', 'GROK-Video');
            iframeNode.setAttribute('height', height+40);
            iframeNode.setAttribute('width', width + 40);
            iframeNode.setAttribute('src', '/kbs/Video.aspx?videoId=1&height=' + height + '&width=' + width);
            iframeNode.setAttribute('frameBorder', 0);
            iframeNode.setAttribute('scrolling', 'no');
            var newFakeImage = e.createFakeElement(iframeNode, 'cke_GROKVideo', 'iframe', true);
            e.insertElement(newFakeImage);
        }
    }
}

The magic is in the editor’s createFakeElement function. It replaces my iframe with a dummy element that is displayed as whatever image I choose with this bit of CSS in my plugin.js:

editor.addCss(
    'img.cke_GROKVideo' +
    '{' +
        'background-image: url(' + CKEDITOR.getUrl(this.path + 'images/YouTubePlayButton.png') + ');' +
        'background-position: center center;' +
        'background-repeat: no-repeat;' +
        'border: 1px solid #a9a9a9;' +
        'width: 80px;' +
        'height: 80px;' +
    '}'
);

Well I’ve gotten pretty far, but the problem arises when the source is viewed. The image turns back into an iframe and the iframe plugin replaces it with its own placeholder! Even worse, when the document is saved and reopened for editing, the same thing happens. How can I keep my play-button placeholder without breaking or replacing the built in iframe plugin placeholder? The pagebreak plugin seems to do something similar with div, but I’m not sure how CKEditor distinguishes between a pagebreak div and an ordinary div when it puts the fake elements in the editor. Has anyone tried something like this? I would prefer to not create a custom HTML element on my website just for this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T00:09:25+00:00Added an answer on June 2, 2026 at 12:09 am

    The solution consists of only two changes to your files:

    Add this to your plugin.js

    (function () {
        [...]
        CKEDITOR.plugins.add('yourPluginNName', {
            init: .... ,
            afterInit: function(editor){
                var dataProcessor = editor.dataProcessor,
                    dataFilter = dataProcessor && dataProcessor.dataFilter;
    
                if ( dataFilter )
                {
                    dataFilter.addRules(
                        {
                            elements :
                            {
                                iframe : function( element )
                                {
                                   if( element.attributes["class"] && element.attributes["class"].indexOf( "GROK-Video" ) >= 0 ){
                                     var e = editor.createFakeParserElement( element, 'cke_GROKVideo', 'iframe', true );
    
                                     // if you want add a thumbnail background or other 
                                     // styles then do it here. 
                                     // but note that it's a parser element, not an html 
                                     // element, it goes something like this: 
                                     e.attributes["style"] += "background: url( ... );"; 
                                     return e;
                                   }
                                   else{
                                     return element;
                                   }
                                }
                            }
                        }, 3); //Priority allows this to overrule the iframe plugin.
                }
            }
        })
    })();
    

    What this effectively does is it hooks into the editors initial transformation step,
    if it encouters an iframe element it replaces it with a fake element.

    Also note that it only replaces the element if it’s class-name is GROK-Video, all other iframe’s will remain unharmed.

    This is great if you have multiple different media plugins.

    Disable the iframe plugin in your config:

    That’s easy:

    config.removePlugins = "iframe";
    

    Maybe you can tell the iframe plugin to be friends with your plugin, but I don’t needed it and I just couldn’t be bothered.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There exists the multisite plugin ( http://github.com/dasil003/rails-multisite/tree/master ) that allows for multiple view folders
In the code there exists exactly one type that implements IResourceConverter. That's what the
I am wondering if there exists a built in class which provides a functionality
I know there exists a command like jQuery.noConflict. But for this it first registers
For Android there exists an open source library called ACRA which allows you to
I was wondering if there exists an application for mobile phones(any platform) that simulates
With ant there exists the echo markup: <echo message="Hello, world"/> but it seems useless.
I know there exists many questions about this, but I dont know what to
I'm wondering if there exists a python module that would allow me to do
There exists a Perl module that provides the perfect functionality for my Python app.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.