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

  • Home
  • SEARCH
  • 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 503239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:22:25+00:00 2026-05-13T06:22:25+00:00

I am having a Javascript kerfuffle that goes beyond my knowledge of the language.

  • 0

I am having a Javascript kerfuffle that goes beyond my knowledge of the language.

I am creating a custom plugin for CKEditor. The plugin is an IFrame that opens in a DIV generated by CKEditor.

Inside the IFrame, I am displaying a number of images. If the user selects one of those images, the HTML code necessary to display that image is inserted into the CKEditor.

Dynamically doing this is where I’m stuck. I am connecting to the CKEditor instance from within the Iframe like so:

var CKEDITOR = window.parent.CKEDITOR;    

CKEditor offers an “OK listener” that triggers when the OK button (rendered by CKEDitor) is clicked. That OK listener is outside the IFrame.

Defining an OK listener that works with static values works:

var okListener = function(ev) {
   this._.editor.insertHtml('<img class="symbol" src="my_static_symbol.gif">');
   CKEDITOR.dialog.getCurrent().removeListener("ok", okListener);
};

// Assign OK listener
CKEDITOR.dialog.getCurrent().on("ok", okListener);

But I don’t know my return value yet when I assign the OK listener, so I would need to do something like this:

var okListener = function(ev) {
   this._.editor.insertHtml('<img class="symbol" src="'+my_dynamic_value()+'">');
   CKEDITOR.dialog.getCurrent().removeListener("ok", okListener);
};

// Assign OK listener
CKEDITOR.dialog.getCurrent().on("ok", okListener);

But this doesn’t work because my_dynamic_value is outside the function’s scope at the time it is fired by CKEditor’s “OK” button.

I could of course, every time the user selects a different image in the list, update the okListener function and hard-code the current value using eval into it. But that feels like a horrible waste of resources to me.

Is there some scope trick I can use so I can access stuff from my Iframe from within okListener()?

I hope this is clear enough. If it isn’t, comment and I will clarify.

  • 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-05-13T06:22:26+00:00Added an answer on May 13, 2026 at 6:22 am

    But this doesn’t work because
    my_dynamic_value is outside the
    function’s scope at the time it is
    fired by CKEditor’s “OK” button.

    OK. Maybe it really doesn’t work, but the explanation is wrong. In JavaScript, variables have lexical scope. This means that if my_dynamic_value is in the scope when your function (handler) is declared, then it remains there forever. What error message are you getting?

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

Sidebar

Ask A Question

Stats

  • Questions 245k
  • Answers 245k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Start a single thread that will do the job of… May 13, 2026 at 8:17 am
  • Editorial Team
    Editorial Team added an answer Sounds like a job for java.util.concurrent.ThreadPoolExecutor. You can set this… May 13, 2026 at 8:17 am
  • Editorial Team
    Editorial Team added an answer The best tool for this kind of task is XPath.… May 13, 2026 at 8:17 am

Related Questions

I am having a JavaScript namespace say A={ CA: function() { this.B(); }, B:
I worked for a company that had both Java and .NET implementations of an
Simple setup: Shopping Cart in the form of a data list. Header has two
Before I post my problem here, please be noted that i would really like
I noticed that the production version of jquery has one-letter function and variable name

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.