Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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 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

1 Answer 1

up vote 3 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

 
discard

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.