|
Getting Content of Editor
There are several approaches for getting the content of the editor depending on the exact usage. Here are explained the most common:
- Using the getContent() and getBodyContent() javascript functions
- Using the saveRemote functionalities to send the content of the editor directly to the server
- Using upload multipart content functionalities to send all embedded local images and hypelink targets
1) Using the getContent() and getBodyContent() javascript functions:
When using the applet, you can get the content of the editor using javascript:
- using htmleditor.getContent() - will return the entire content of the page
- using htmleditor.getBodyContent() - will return only the content of the body
When you are using a form element you should get the content from the editor using one of the functions above and place it for example in to a hidden field in the form. After that the entire form can be submitted to the server.
Here below is supplied an example script that sends all the content of the editor from a FORM element using the variable "html_content" - note the usage of the onSubmit() form handler:
This example will work on almost all browsers on all platforms without any modification. It will work on Windows (IE, Netscape, Mozilla, Opera, FireFox etc.), Linux (Netscape, Mozilla, FireFox, Konqueror, Galeon, Opera), Solaris (Netscape, Mozilla, FireFox, Konqueror, Opera), Sun JavaDesktop System (Netscape, Mozilla, FireFox, Konqueror, Galeon, Opera), and Safari 1.2 on Mac OS X. For the browsers that do not support the java-javascript communication directly (IE 5.2, Mozilla on Mac OS X) is necessary the Sferyx LiveConnect Proxy which is included with all retail products but not in the downloadable demo version. See the LiveConnect Proxy section for major details.
2) Using the Save Remote functionalities:
The Save Remote functionalities is very useful when you need to edit a document, and make feel your users that they are using any word processing application. Using the Save Remote functionalities they can save the document directly from the editor by hitting "Save Remote" on the File menu or if configured properly, they can use the toolbar shortcut icon "Save" to save the content remotely.
The editor will send the content to the server as POST data contained in the variable html_content which is the default name. If you want to change it, you can use the following parameter:
<PARAM NAME ="variableName" VALUE="htmlcontent">
The URL of the script should be defined in the following parameter:
<PARAM NAME ="saveURL" VALUE="http://www.sferyx.com/htmleditorapplet/demo/form_dump.php">
The saveURL parameter should be a fully qualified absolute URL with http://.. etc. Note that when posting the data to the server, the applet will not change the page in your browser - it works exactly as when you save a file to your local computer with the difference that it sends it remotely. If there occurs an error, error message will be displayed, otherwise on the status bar will appear " File saved successfully".
This approach is very useful for example when you need to edit a complex document and also you using the external window editor mode. This way you will feel as using any normal word processing application, because at the end of the editing itwill be sufficient to hit the "Save" icon or "Save Remote" menu item and simply close the window when "File Saved Successfully" message appears.
For advanced configuration you may use the following additional parameters.
<PARAM NAME="useSaveAsSaveRemote" VALUE="true|false"> - this will cause all buttons/menus for save to have the behavior of "Save Remote" functionality. This way also the shortcut on the toolbar ("the save floppy icon") can be used to save the content of the editor remotely. The default is false.
<PARAM NAME="saveEntireFile" VALUE="true|false"> - this parameter specifies whether the "Save Remote" functionality should send entire HTML files (including <html><head><body> tags) or should send only the body content as a page fragment.
Server side scripts for receiving the posted from the editor content
1.) ASP/.Net example - This a simple script which will receive the html content posted from the editor and will save it in a file on the server. In this example we presume that the content will be posted in the variable "htmlcontent" . The received content will be saved to a sample file test.htm in the directory specified in the variable saveDirVar
»
|