2

How to pass arguments from tinyMCE to tinyMCEPopup?

I saw this solution: TinyMCE - Pass value from Popup

and I'm looking for something else? How do I create a variable in tinyMCE which I can access in tinyMCEPopup?

Community
  • 1
  • 1
petko_stankoski
  • 10,459
  • 41
  • 127
  • 231

2 Answers2

3

There are several ways to access variables from a tinymce popup.

A. You may assign a variable to your editor object and later on access it from the popup: tinyMCEPopup.editor.my_variable = 'xyz';

B. You may assign a variable to your window object (from the maindocument): window.my_variable = 'xyz'; and access it later on using the openObject in case your popup is an own window: window.opener.my_variable.

Does this solve your issue?

Thariama
  • 50,002
  • 13
  • 138
  • 166
1

Each popup is an IFrame, which means that you can prefix any variable you want in the popup with window.parent. (like window.parent.[variable name]) to access any variable on your page.

Also, because the popup is an iframe, you can't actually directly pass in a variable on the window creation. But if you get a reference to the new iframe object directly you can of course get and set variables after the frame has been loaded.

Another option to consider would be to pass variables in on the url of the page you are loading.

Reimius
  • 5,694
  • 5
  • 24
  • 42
  • no, not each popup is an iframe - that depends on the use of the inlinepopups plugin – Thariama Apr 02 '12 at 13:31
  • Since that is a plugin... and not the default behavior, I did not assume the asker was using it. – Reimius Apr 02 '12 at 15:41
  • Also, your solution below, while it does work, assumes that he wont name his variable something already used by the editor object, while highly unlikely, is still possible. – Reimius Apr 02 '12 at 15:44
  • Correct, inlinepopups is a plugin, but one that gets shipped with tinymce and can be included using the configuration (i think most users use this). He can easily check if that variable name is already taken printing out the editor object and check its variables (using a web developer tool like firebug). – Thariama Apr 03 '12 at 07:42