tinyMCE,根据打开的链接更改内容
我有两个链接可以打开嵌入在 fancybox 中的tinyMCE。
现在我想根据用户点击的链接更改里面的内容,我想在tinyMCE中显示的内容是我点击的链接。
我尝试设置 $('.editor').html($(this).html()) 并且它第一次工作,显示正确的内容。
但这是我的问题,内容被“卡住”,当我关闭我的 fancybox 并单击另一个链接时,第一个内容仍然存在。
无论如何我可以重置tinyMCE吗?我尝试设置 $('editor').text('') 并删除内容,但当我单击按钮时它不会返回。
它可能与tinyMCE生成的iframe有关,但我无法让它工作...
这是我当前的代码...
HTML ” />
<!--File2-->
<div class="title">
<a href="#mce" class="edit"><h2>Titel</h2></a>
</div>
<div class="content">
<a href="#mce" class="edit">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Ut aliquam diam eget elit tristique sit amet fringilla velit sagittis.
Nam aliquet, nisl eget elementum consectetur, felis arcu feugiat felis, vel fermentum mi ipsum vitae neque.
Suspendisse placerat leo dolor, ut mollis elit. Nullam bibendum posuere risus tempus viverra.
Aliquam in erat dui. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Aenean auctor lacinia erat, ut facilisis lorem scelerisque eu.
Duis vitae ullamcorper felis. Pellentesque blandit tortor quis magna placerat eget iaculis velit commodo.
Nam imperdiet auctor scelerisque. Proin fermentum sem in nulla ornare euismod.
Maecenas faucibus facilisis cursus. Proin tincidunt luctus egestas.
Curabitur vestibulum aliquet viverra.
</p>
</a>
</div>
javascript
$('.editor').html('');
var content = $(this).html();
$('.editor').html(content);
$(this).fancybox(
{
'size' : 'auto',
'onComplete': function()
{
$('.editor').tinymce(
{
script_url : '/media/tiny_mce/tiny_mce.js',
theme : 'advanced',
height: 450,
plugins : 'ecmsimage,pagebreak,style,layer,table,save,advhr,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,advlist',
theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,formatselect,fontselect,fontsizeselect",
theme_advanced_buttons2 : "bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,cleanup,help,|,insertdate,inserttime,|,forecolor,backcolor",
theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,|,sub,sup,|,charmap,iespell,advhr,|,code,preview,fullscreen",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_statusbar_location : "bottom",
theme_advanced_resizing : true,
theme_advanced_resize_horizontal: false
});
$('#fancybox-inner').width(550).height(500);
$('#fancybox-wrap').width(550).height(500);
$.fancybox.center();
}
});
I've got two links that opens a tinyMCE embedded inside a fancybox.
Now i'd like to change the content inside depending on what link the user clicks on, the content that i want to show inside tinyMCE is the link that im clicking on.
I've tried to set $('.editor').html($(this).html()) and it works the first time, the right content gets shown.
BUT here's my problem, the content gets 'stuck', when i close my fancybox and clicks the other link then the first content is still there.
Is there anyway i can reset the tinyMCE? I've tried setting $('editor').text('') and that removes the content but it wont get back when i click the button.
it probably has something to do with the iframe that tinyMCE produces, but i can't get it to work...
Here is my current code...
HTML
" />
<!--File2-->
<div class="title">
<a href="#mce" class="edit"><h2>Titel</h2></a>
</div>
<div class="content">
<a href="#mce" class="edit">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Ut aliquam diam eget elit tristique sit amet fringilla velit sagittis.
Nam aliquet, nisl eget elementum consectetur, felis arcu feugiat felis, vel fermentum mi ipsum vitae neque.
Suspendisse placerat leo dolor, ut mollis elit. Nullam bibendum posuere risus tempus viverra.
Aliquam in erat dui. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Aenean auctor lacinia erat, ut facilisis lorem scelerisque eu.
Duis vitae ullamcorper felis. Pellentesque blandit tortor quis magna placerat eget iaculis velit commodo.
Nam imperdiet auctor scelerisque. Proin fermentum sem in nulla ornare euismod.
Maecenas faucibus facilisis cursus. Proin tincidunt luctus egestas.
Curabitur vestibulum aliquet viverra.
</p>
</a>
</div>
javascript
$('.editor').html('');
var content = $(this).html();
$('.editor').html(content);
$(this).fancybox(
{
'size' : 'auto',
'onComplete': function()
{
$('.editor').tinymce(
{
script_url : '/media/tiny_mce/tiny_mce.js',
theme : 'advanced',
height: 450,
plugins : 'ecmsimage,pagebreak,style,layer,table,save,advhr,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,advlist',
theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,formatselect,fontselect,fontsizeselect",
theme_advanced_buttons2 : "bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,cleanup,help,|,insertdate,inserttime,|,forecolor,backcolor",
theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,|,sub,sup,|,charmap,iespell,advhr,|,code,preview,fullscreen",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_statusbar_location : "bottom",
theme_advanced_resizing : true,
theme_advanced_resize_horizontal: false
});
$('#fancybox-inner').width(550).height(500);
$('#fancybox-wrap').width(550).height(500);
$.fancybox.center();
}
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在关闭 fancybox 之前,您需要正确关闭tinymce,以便能够再次打开tinymce编辑器。使用它可以正确关闭它
editorid 等于您初始化tinymce 的html 元素的id。
You need to shut down tinymce correctly before closing the fancybox in order to be able to open the tinymce editor a second time. Use this to shut it down correctly
The editorid equals the id of your html element for which you initialize your tinymce.