开发者

Yahoo YUI 2 - Rich Text Editor - can't get setEditorHTML method to work, what's wrong?

Today, for the first time, I came across the YUI 2 Rich Text Editor. (http://developer.yahoo.com/yui/editor/)

I mainly use Java Server Pages for my websites.

I want to be able to set the text in the textarea of the Editor to a previously submitted value. As an example, when a user submits the page, after having entered text in the Editor, that text may be saved in a database for future use. I would then call the value from the database, and set the Editor to display it at that point, so the user could make modifications.

I found a method in the API documentation called setEditorHTML() - but for some reason or another, I can't get it to work.

Here is the test code I've been playing around with. I'm testing in Firefox.

I don't understand why the setEditorHTML method won't work...can someone please assist me?

<html>

<head>

<% String editorText = (String)session.getAttribute("editorText"); %>


<!-- Individual YUI CSS files -->
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.9.0/build/assets/skins/sam/skin.css">
<!-- Individual YUI JS files -->
<script type="text/javascript" src="http://yui.yahooapis.com/2.9.0/build/yahoo-dom-event/yahoo-dom-event.js"></script>

<script type="text/javascript" src="http://yui.yahooapis.com/2.9.0/build/element/element-min.js"></script>
<script type="text/javascript" src="http://yui.yahooapis.com/2.9.0/build/container/container_core-min.js"></script>
<script type="text/javascript" src="http://yui.yahooapis.com/2.9.0/build/menu/menu-min.js"></script>
<script type="text/javascript" src="http://yui.yahooapis.com/2.9.0/build/button/button-min.js"></script>
<script type="text/javascript" src="http://yui.yahooa开发者_开发问答pis.com/2.9.0/build/dragdrop/dragdrop-min.js"></script>
<script type="text/javascript" src="http://yui.yahooapis.com/2.9.0/build/slider/slider-min.js"></script>
<script type="text/javascript" src="http://yui.yahooapis.com/2.9.0/build/colorpicker/colorpicker-min.js"></script>

<script type="text/javascript" src="Yahoo-YUI-editor/editor-min.js"></script>
<script type="text/javascript" src="http://yui.yahooapis.com/2.9.0/build/layout/layout-min.js"></script>


<script language="javascript">
var myEditor = new YAHOO.widget.Editor('msgpost', {
    height: '300px',
    width: '522px',
    dompath: false, //Turns on the bar at the bottom
    animate: false, //Animates the opening, closing and moving of Editor windows
    handleSubmit: true
});

myEditor.render();

<% if(editorText != null) {
     out.print("myEditor.setEditorHTML(\""+editorText+"\");");         
       }
%>

</script>

</head>

<body class="yui-skin-sam">

<form name="editor" action="YahooEditor.jsp" method="post">
<textarea name="msgpost" id="msgpost" cols="50" rows="10"></textarea>
<input type="submit" value="submit"/>
</form>
</body>
</html>


There is a time while the editor is rendering which you cannot access setEditorHTML. Try this:

var myEditor = new YAHOO.widget.Editor('msgpost', {
    height: '300px',
    width: '522px',
    dompath: false, //Turns on the bar at the bottom
    animate: false, //Animates the opening, closing and moving of Editor windows
    handleSubmit: true
});

myEditor.render();
// I just took a guess on which event to use here
myEditor.on('windowRender', function() {
    myEditor.setEditorHTML("Hello World");

});

Here is a list of YUI Editor events.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜