单击“自定义功能区"操作,将HTML代码插入SharePoint中的编辑器中 [英] Insert HTML code into the Editor in SharePoint on click of Custom Ribbon action

查看:70
本文介绍了单击“自定义功能区"操作,将HTML代码插入SharePoint中的编辑器中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当名为插入代码"的功能区出现在页面上时,我正在向页面插入一段代码.单击功能区中存在的 页面编辑模式).这是我使用的代码:

I am inserting a piece of code to the Page, when a ribbon named "Insert Code" which is present in the ribbon is clicked(on page edit mode). Here is the code i use:

 <script type="text/javascript">//<![CDATA[
            function Warn()
{
            var href = '<div class="my-class"><h1>The Header</h1><p>The paragraph of text</p>';

       var range = RTE.Cursor.get_range();
                 range.deleteContent();
                 var selection = range.parentElement();
                 if (!selection) {
                     return;
                 }
                 var span = selection.ownerDocument.createElement('span');
                 span.innerText = href;
                 range.insertNode(span);
                 RTE.Cursor.get_range().moveToNode(span);
                 Range.pasteHtml(href);
                 RTE.Cursor.update();                   
    }     
            //]]>

         </script> 

我可以在页面上添加代码.但其插入方式如下,而不是实际的html标签.有关如何纠正它的任何信息?

<p>​​<span>&lt;div class=&quot;my-class&quot;&gt;         &lt;h1&gt;The Header&lt;/h1&gt;         &lt;p&gt;The paragraph of text&lt;/p&gt;         &lt</span><br/></p>

推荐答案

您的代码 [ span.innerText = href;] 不正确,应该是 [ span.inner = href;] .请更改它,然后重试.

Your code [span.innerText = href;] is not right, it should be [span.innerHTML= href;]. Please change it and try again.

最好的问候,

李e


这篇关于单击“自定义功能区"操作,将HTML代码插入SharePoint中的编辑器中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆