modifying the contents of the FCKeditor editor

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

modifying the contents of the FCKeditor editor

Post by Burrito »

I could dig through this code to figure it out, but I thought I'd just ask first.

does anyone know a quick and easy way to modify the contents of the editor frame for FCKeditor using JS.

example:

I have an instance of FCKeditor loaded on my page, and I want to change the contents of the iframe using a select box or somethign similar.

I can't simply change the src element because that just changes the page source and removes the editing capabilites.

anyone done this?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Are you asking how you change the text that is in the FCKEditor box itself? I am a little unclear on the question. Also, does it have to be an iFrame, or can you resort to a textarea?
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

Everah wrote:Are you asking how you change the text that is in the FCKEditor box itself?
yes
Everah wrote:Also, does it have to be an iFrame, or can you resort to a textarea?
must be iframe.

I'm using the php version (to build the editor).
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

The id of the iframe is 'editor___Frame'. Inside that, I believe the code is displayed in a table cell with id 'xEditingArea'.

Failing finding a way to get that to work, you could try the poorly commented, but likely well built API:

http://wiki.fckeditor.net/Developer%27s ... script_API
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

excellent...I'll give that a try.

thx pickle.
godforhire
Forum Newbie
Posts: 1
Joined: Mon Jul 24, 2006 8:49 am

Post by godforhire »

I had a similar problem and couldn't find any info on it. However, after some trial and error, I've managed to retrieve the contents of the text inside the xEditingArea. Below is the code (test on Firefox only), hope it's of some use:

Code: Select all

function showFC() {
	var contents;
	ifrRef =document.getElementById('editor___Frame');
	var hCode = ifrRef.contentDocument.getElementById("xEditingArea");
	var iFCode = hCode.getElementsByTagName("IFRAME")[0];
	contents = iFCode.contentDocument.getElementsByTagName("BODY")[0].innerHTML
	alert(content);
}
(To use with IE, I believe you have to change 'contentDocument' to 'contentWindow'.)
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

if you just want to retrieve the page that's in the editor, all you need to do is use the API object that is provided:

Code: Select all

oEditor = FCKeditorAPI.GetInstance('theEditor') ;
            var fileContents = oEditor.GetXHTML();
as to the OP's question, prior to loading the editor it's easy, after it's loaded, I'm not too sure...
Post Reply