using SharePoint 2013 I've added a blog post. This blog post requires me to run some JavaScript after it has been loaded. I am also using jQuery, so I tried the standard $(myInitFunction) to no avail - it fires before the blog post content is loaded.

I also tried SP.SOD.executeOrDelayUntilEventNotified but I'm not sure which event to subscribe to, not could I find a list of event names.

I also tried a few other things that didn't work.

So, how can I execute a JavaScript function after the blog post has finished loading?

4 Answers 4


Since in SharePoint 2013 was introduced Client Side Rendering that represents HTML/JavaScript rendering framework for list views & forms (follow, for example, this article for an introduction), below is demonstrated how invoke a custom code in OnPostRender event:

SP.SOD.executeFunc("clienttemplates.js", "SPClientTemplates", function() {

  function init() {
      OnPostRender: function(ctx) {
         //your code goes here...

  RegisterModuleInit(SPClientTemplates.Utility.ReplaceUrlTokens("~siteCollection/Style Library/blog.js"), init);


How to apply the changes

  1. Save the specified script as blog.is file and upload it into Style Library
  2. Go to page Edit mode and then open Blogs web part in Edit mode
  3. For JSLink property specify: ~siteCollection/Style Library/blog.js
  4. Save the changes

Have you tried this

<script language="javascript">  
    function StartFunction()   


function LoadAfterFunction(){
    //your code

ExecuteOrDelayUntilScriptLoaded(LoadAfterFunction, "sp.ui.blogs.js")
  • Yes, and I meant to add that to the list of things I've tried. This appears to happen too soon as well. Apparently the blog content is loaded asynchronously?
    – Josh M.
    Commented Apr 10, 2015 at 17:32
  • @JoshM. try my updated answer. Commented Apr 10, 2015 at 17:38
  • Okay, just tried your latest suggestion as well as SP.SOD.executeOrDelayUntilScriptLoaded but my init function is never fired (debugging in Chrome). Even though I can clearly see that "sp.ui.blogs.js" has been loaded...
    – Josh M.
    Commented Apr 10, 2015 at 17:51
  • For the time being I've resorted to executing my init function on page load and then again 2 seconds later, since it is re-runnable, but I really hate doing that.
    – Josh M.
    Commented Apr 10, 2015 at 17:53

Perhaps this will work for you. It's worth a try

  //your code

This triggers after everything is loaded according to the jQuery docs. However this does not include asynchronous loading according to the docs below.


Another trick (in SharePoint 2010 at least) is to add the JS code in a webpart below the webpart you are trying to modify using jQuery.

Also possibly related are the settings of the blogpost webpart (asuming there is one), maybe settings there can be changed to prevent async loading.

  • Right, but it has to happen after the blog post is asynchronously loaded.
    – Josh M.
    Commented Apr 10, 2015 at 20:07
  • I'm no expert on SP2013 but is it not possible to override The view of the blogpost webpart and add the script to the bottom there? Commented Apr 10, 2015 at 20:09
  • Yes but I need it to happen for every blog post, or close to it. So it's not feasible to do this for each and every one. This JS is included on the page already, I just need to hook up to some event to run it after the blog post is loaded.
    – Josh M.
    Commented Apr 10, 2015 at 20:11

You can test the HTML Placeholder where the blog post will append. While it's empty don't do anything. When the content is there, execute your code. Just use a function with a setTimeout that calls itself and that tests if the content arrived. Make sense?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.