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

六眼飞鱼酱① 提交于 2019-12-12 04:29:13

问题


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.yahooapis.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>

回答1:


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.



来源:https://stackoverflow.com/questions/7016105/yahoo-yui-2-rich-text-editor-cant-get-seteditorhtml-method-to-work-whats

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!