Вопрос

I have added a content editor web part in a SharePoint web part page. I have some java script code logic which renders some HTML and I have added that script to content editor web part Content Link.

Is it possible to read the current content editor web part Id or any unique property of the current content editor web part from the script being linked in Content Link?

Thanks.

Это было полезно?

Решение

Add this to the file linked using Content Link to show WebPart ID. Requires jQuery.

<div id="mySpan"></div>
<script>
    $("#mySpan").closest("div[WebPartID]").attr("WebPartID")
</script>

Другие советы

NOT TESTED - pulled it from old code

Without jQuery and not requiring a 'marker' DIV to know where your code is

Since you can add events to an IMG tag

<span>
  <img onerror="
                var el=this;
                while (!(el.getAttribute(dataAttr) || el===document.body))el=el.parentNode;
                var id=el.getAttribute(dataAttr);
                this.parentNode.innerHTML=id;
    ">
</span>

Should result in:

<span>
  3766612-68c3-46cf-bb31-f0725c7f71f
</span>
Лицензировано под: CC-BY-SA с атрибуция
Не связан с sharepoint.stackexchange
scroll top