将iframe内容作为字符串 [英] get iframe content as string
问题描述
我使用jquery插件生成富文本编辑器。该编辑器生成如下结构:
I use a jquery plugin for generating rich text editor. That editor generates an structure like this:
<div id="editor" ... >
...
<iframe>
<!DOCTYPE html>
<html>
<head>...</head>
<body>
//some important content here and I need to get them
</body>
</html>
</iframe>
</div>
现在,我想把iframe的所有内容都作为 String 。我测试了 $(#editor)。contents()。find(body)
,但这会返回一个对象,而不是字符串。还尝试了 $(#editor)。contents()。find(body)。outerHTML
,但这还给我 undefined
。我怎样才能做到这一点?请帮帮我。感谢您的时间。
Now, I want to get everything inside iframe's body as an String. I tested $("#editor").contents().find("body")
, but this return me an object, not string. Also tried $("#editor").contents().find("body").outerHTML
, but this return me undefined
. How can I do this? Please help me. Thank you for your time.
修改:
我使用 SCEditor 插件。正如Ramesh所说,我使用 val()
方法,但仍然在firebug控制台中返回(空字符串)
。这是我的代码:
I use SCEditor plugin. As Ramesh said, I used val()
method, but still return me (an empty string)
in the firebug console. Here is my code:
var instance = $("textarea").sceditor({
plugins: "bbcode",
style: "../../editor/minified/jquery.sceditor.default.min.css",
//some othe options
});
$("#save").click(function(){
console.log(instance.val());
});
正如Ramesh所说,我使用 $('textarea')。sceditor( 'instance')。val()
并且它有效。
As Ramesh suggests, I used $('textarea').sceditor('instance').val()
and it worked.
推荐答案
在SCEditor中获取富文本框的值,你必须使用 .val
方法
In SCEditor to fetch the value of the rich text box, you have to use the .val
method
val()从:1.3.5
val() Since: 1.3.5
获取编辑器的当前值。
这将返回WYSIWYG编辑器中过滤的HTML或源编辑器的
未过滤内容。
This will return the filtered HTML from the WYSIWYG editor or the unfiltered contents of the source editor.
如果使用插件像BBCode插件那样过滤HTML,在BBCode
插件的情况下,这个
将返回过滤后的HTML或BBCode。
If using a plugin that filters the HTML like the BBCode plugin, this will return the filtered HTML or BBCode in the case of the BBCode plugin.
语法
var val = instance.val();
返回类型:字符串
编辑器的过滤值
这篇关于将iframe内容作为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!