SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I currently have a JavaScript file that gets loaded in my SharePoint pages.

jQuery(document).ready(function() {
 ExecuteOrDelayUntilScriptLoaded(myfunction(), "sp.js");

myfunction = function(){
 /*Do something here.*/

Now the JavaScript runs just fine, however on a list page, it prevents the ribbon from loading the List tab. In the console I get below error.

SCRIPT5007: Object expected init.debug.js, line 5153 character 5 error.

Even if I comment out all of the function so it looks exactly like above I still get the error message.

I have noticed that if I change "sp.js" to "sp.debug.js" I do not get the error message. From looking at the scripts that are loaded on the page, this makes sense as sp.debug.js is loaded and not sp.js. I don't really want to put sp.debug.js in the javascript code as when it reaches production servers, they won't be using sp.debug.js. I've never notice this happen before with any code that has ExecuteOrDelayUntilScriptLoaded(jsfunction(), "sp.js"). Is there a way to get it to work for both environments like with a #ifdebug statement in javascript? Or some other idea.

share|improve this question
up vote 18 down vote accepted

You are using ExecuteOrDelayUntilScriptLoaded wrong, you should use the function name, not execute it.

Like this:

jQuery(document).ready(function() {
 ExecuteOrDelayUntilScriptLoaded(myfunction, "sp.js");

Note that i removed the "()" from myfunction. Now it should work as expected

share|improve this answer
Thank you. School boy error! Glad you spotted it. Thanks. – Cann0nF0dder Sep 4 '13 at 9:51

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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