I'm reposting my code here so as to help spread the word.
Background:
The Link and Image buttons (as well as others) in CKEditor will show a dialog box asking you for a URL. You have the option to set a Browser Server button in one of these box's in your config file which can point to some kind of file browser, probably some other portion of your system or CMS. The challange is then to return a URL form your code back to the CKEditor window. Normally this is quite easy with something like this.
strURL += "javascript:window.opener.document."; strURL += "getElementById('" + strReturnControlID + "')"; strURL += ".value='/" + strPageTitle.Replace("'", "\\'"); strURL += "'; window.close()";Where strReturnControlID would contain the ID of the parent textbox from the querystring that I set in the CKEditor Config for the Browser Server button. Problem is, this ID changes, often with each page reload. Lame.
Solution:
The solution is to use the CKEditor API to do the heavy lifting.
strURL += "javascript:window.parent.opener.CKEDITOR.tools.callFunction("; strURL += Request.QueryString["CKEditorFuncNum"].ToString(); strURL += ", '" + strPageTitle.Replace("'", "\\'") + "', '' ); window.close();";I was quite surprised when this worked the first time!
The CKEditorFuncNum isn't something you have to worry about, the CKEditor auto passes the correct value for you.
Hope this helps someone else, let me know if you need any further clarification.
0 comments:
Post a Comment