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

Using a CustomAction in the location of a scriptlink, I'm inserting a javascript code, however I need this code to run after core.js runs. Does anyone know how I can achieve this?

My CustomAction elements file looks like this.

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <CustomAction Location="ScriptLink" Sequence="10000"  ScriptBlock="
                var domain = document.domain;
                /* 
                   rest of my Javascript Code */
};"/>
  </Elements>

I have tried to put my code within a function, and call ExecuteOrDelayUntilScriptLoaded but that didn't seem to work either.

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <CustomAction Location="ScriptLink" Sequence="10000"  ScriptBlock="
                ExecuteOrDelayUntilScriptLoaded(MyCode, 'core.js');

                function MyCode(){ 
                      var domain = document.domain;

                   /*rest of my Javascript Code */
    };"/>
      </Elements>

Can anyone help me?

share|improve this question
    
The way you are using it should work. Can you see the script on the page? Are you getting any JS errors on the page? –  Vardhaman Deshpande Oct 26 '12 at 13:51
    
I'm getting no JS errors, and the script is loading according to IE developer toolbar. The JS is written by a 3rd party, and they told us it needs to be run after core.js, so perhaps there is actually a problem with their code, we have already found a few mistakes. –  Cann0nF0dder Oct 29 '12 at 9:48
add comment

1 Answer

up vote 2 down vote accepted

Please have a look in here Paul, this might help you out.

http://ensure.codeplex.com/

Also Waldek provides an extensive overview of the problem in his blogpost, http://blog.mastykarz.nl/dynamically-loading-javascript-sandbox/ , which suggest some ways to get around the sandbox' limitations with regards to loading scripts.

share|improve this answer
    
This is a very good answer. It didn't solve my problem as I now think the problem is with the js code, not with order I run it in. I've marked it as correct answer as it did confirm, and also offer me different ways to run js code in different order, which will be very helpful in SP2013. –  Cann0nF0dder Oct 29 '12 at 9:51
add comment

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.