Line 1: | Line 1: | ||
− | == Frequently Asked Questions : JavaScript == | + | __NOTOC__ |
+ | == Frequently Asked Questions : JavaScript == | ||
* [[#tabindex|How do I apply a tabindex on the FCKeditor?]] | * [[#tabindex|How do I apply a tabindex on the FCKeditor?]] | ||
Line 5: | Line 6: | ||
* [[#sethtmlnotworking|.SetHTML doesn't work! Why not?]] | * [[#sethtmlnotworking|.SetHTML doesn't work! Why not?]] | ||
* [[#javascriptParent|How do I call a javascript function on the page containing the editor from a plugin?]] | * [[#javascriptParent|How do I call a javascript function on the page containing the editor from a plugin?]] | ||
− | * [[ | + | * [[FCKeditor 2.x/Developers Guide/FAQ/JavaScirpt/OnkeyEvent|How do I capture an onkey event within FCKeditor?]] |
=== <span id="tabindex">How do I apply a tabindex on the FCKeditor?</span> === | === <span id="tabindex">How do I apply a tabindex on the FCKeditor?</span> === | ||
Line 28: | Line 29: | ||
Just use the FCKeditor JavaScript API: | Just use the FCKeditor JavaScript API: | ||
− | <pre> | + | <pre>function getEditorValue( instanceName ) |
− | function getEditorValue( instanceName ) | ||
{ | { | ||
− | + | // Get the editor instance that we want to interact with. | |
− | + | var oEditor = FCKeditorAPI.GetInstance( instanceName ) ; | |
− | + | // Get the editor contents as XHTML. | |
− | + | return oEditor.GetXHTML( true ) ; // "true" means you want it formatted. | |
} | } | ||
function setEditorValue( instanceName, text ) | function setEditorValue( instanceName, text ) | ||
{ | { | ||
− | + | // Get the editor instance that we want to interact with. | |
− | + | var oEditor = FCKeditorAPI.GetInstance( instanceName ) ; | |
− | + | // Set the editor contents. | |
− | + | oEditor.SetHTML( text ) ; | |
} | } | ||
− | </pre> | + | </pre> |
− | |||
=== <span id="sethtmlnotworking">.SetHTML doesn't work! Why not?</span> === | === <span id="sethtmlnotworking">.SetHTML doesn't work! Why not?</span> === | ||
One possibility is that the argument passed to the .SetHTML function is of the javascript type 'object'. Then the .SetHTML function may not work. If necessary, you can convert an object to a string by calling .toString() on it. So: | One possibility is that the argument passed to the .SetHTML function is of the javascript type 'object'. Then the .SetHTML function may not work. If necessary, you can convert an object to a string by calling .toString() on it. So: | ||
− | <pre> | + | <pre>oEditor.SetHTML( yourObject.toString()); |
− | oEditor.SetHTML( yourObject.toString()); | + | </pre> |
− | </pre> | ||
To find out the type of a given object, just call the typeof() function on it. So: | To find out the type of a given object, just call the typeof() function on it. So: | ||
− | <pre> | + | <pre>typeof(yourObject); |
− | typeof(yourObject); | + | </pre> |
− | </pre> | ||
You can find more samples on how to use the editor API in the "_samples/html/sample08.html" file. | You can find more samples on how to use the editor API in the "_samples/html/sample08.html" file. | ||
Line 64: | Line 61: | ||
If you want to call a function contained in the page that instantiates the FCKeditor, you will need to add "parent." to the function name in the plugin.js. | If you want to call a function contained in the page that instantiates the FCKeditor, you will need to add "parent." to the function name in the plugin.js. | ||
− | Let's say that in fun.html I have a function named "SetSelected". If I were writing a plugin for use on the fun.html page, and I wanted it to call the !SetSelected() function from plugin.js, I would simply have to add parent to it. | + | Let's say that in fun.html I have a function named "SetSelected". If I were writing a plugin for use on the fun.html page, and I wanted it to call the !SetSelected() function from plugin.js, I would simply have to add parent to it. |
E.g. '''parent'''.''SetSelected();'' Sometimes you may have nested the editor another level; just add another parent like: ''parent.parent.SetSelected();'' | E.g. '''parent'''.''SetSelected();'' Sometimes you may have nested the editor another level; just add another parent like: ''parent.parent.SetSelected();'' |
Revision as of 17:44, 18 January 2008
Frequently Asked Questions : JavaScript
- How do I apply a tabindex on the FCKeditor?
- How do I dynamically change the content in the editor with JavaScript?
- .SetHTML doesn't work! Why not?
- How do I call a javascript function on the page containing the editor from a plugin?
- How do I capture an onkey event within FCKeditor?
How do I apply a tabindex on the FCKeditor?
By adding some Javascript:
On the field just before the FCKEditor: <input ... onKeyDown="focusIframeOnTab(this, "idOfYourFckEditorIframe", event);if(!document.all) return false;">
Use this function:
function focusIframeOnTab(caller, tabTargetId, callEvent) { // If keypress TAB and not SHIFT+TAB if(callEvent.keyCode == 9 && !callEvent.shiftKey) document.getElementById(tabTargetId).contentWindow.focus(); }
Remember that the id of the iframe should look like "identifier___Frame".
(Please feel free to write to fredrik@demomusic.dot.nu for suggestions on improving this function. Verified to work in Firefox 1.5 and IE 6 on WinXP)
How do I dynamically change the content in the editor with JavaScript?
Just use the FCKeditor JavaScript API:
function getEditorValue( instanceName ) { // Get the editor instance that we want to interact with. var oEditor = FCKeditorAPI.GetInstance( instanceName ) ; // Get the editor contents as XHTML. return oEditor.GetXHTML( true ) ; // "true" means you want it formatted. } function setEditorValue( instanceName, text ) { // Get the editor instance that we want to interact with. var oEditor = FCKeditorAPI.GetInstance( instanceName ) ; // Set the editor contents. oEditor.SetHTML( text ) ; }
.SetHTML doesn't work! Why not?
One possibility is that the argument passed to the .SetHTML function is of the javascript type 'object'. Then the .SetHTML function may not work. If necessary, you can convert an object to a string by calling .toString() on it. So:
oEditor.SetHTML( yourObject.toString());
To find out the type of a given object, just call the typeof() function on it. So:
typeof(yourObject);
You can find more samples on how to use the editor API in the "_samples/html/sample08.html" file.
How do I call a javascript function on the page containing the editor from a plugin?
If you want to call a function contained in the page that instantiates the FCKeditor, you will need to add "parent." to the function name in the plugin.js.
Let's say that in fun.html I have a function named "SetSelected". If I were writing a plugin for use on the fun.html page, and I wanted it to call the !SetSelected() function from plugin.js, I would simply have to add parent to it.
E.g. parent.SetSelected(); Sometimes you may have nested the editor another level; just add another parent like: parent.parent.SetSelected();