문제

I have added some jQuery code to the DisplayForm as follow-

<asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server">

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script type='text/javascript'>

function Execute_Attachments_Processing(){
  jQuery('table#idAttachmentsTable td a').each(function(){
    var $parent = jQuery(this).parent();

    var a_src = jQuery(this).attr('href');
    var a_text = jQuery(this).text();

    if(a_src.contains('jpg') || a_src.contains('jpeg') || a_src.contains('png') || a_src.contains('gif')){
      jQuery(this).remove();
      $parent.append('<div style="text-align:center; padding-bottom:20px;"><a target="_blank" href="'+a_src+'"><img title="'+a_text+'" src="'+a_src+'" width="300px" /><br/>'+ a_text+'</a></div>');
    }
  });
}

jQuery(document).ready(function(){
    Execute_Attachments_Processing();
});
</script>

// Other html/xml code here..

</content>

It converts attachments into viewable images.

It is not executing at all. What could be the problem?

도움이 되었습니까?

해결책

Use $(window).load(function() {}); instead of document.ready(). It seems your DOM is loading after you are calling the function.

window.load will run after all DOM has been loaded completely.

다른 팁

You might want to use _spBodyOnLoadFunctionNames.push method instead of jQuery's document.ready(), read this article.

Also, other functions available.

If you are on SharePoint 2013/Office 365 check if minimum download strategy is enabled for the site. Disable it and have a try.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 sharepoint.stackexchange
scroll top