Like many question I have seen the jQuery document.ready works in the web-part during editing but not after I save the page. I found this code on SO and thought I run a couple of test to see what was happening, I added a couple of alert boxes to see how jQuery was being loaded. to my surprise the script section is never called? below is how I have my setup any help would be great. I'm using SharePoint 365 2013

<script type="text/javascript" src="../master_page_items/jquery-2.2.0.min.js"></script>
<script type="text/javascript" src="../master_page_items/jquery-ui-1.11.4/jquery-ui.js"></script>
<script type="text/javascript" src="../master_page_items/picture_slider.js"></script>
<script type="text/javascript" src="https://c64.assets-yammer.com/assets/platform_embed.js"></script>


<script language="Javascript" type="text/javascript">

// Only do anything if jQuery isn't defined
if (typeof jQuery == 'undefined') {

if (typeof $ == 'function') {
    // warning, global var
    thisPageUsingOtherJSLibrary = true;

  alert('thisPageUsingOtherJSLibrary NOT DEFINE');
}

function getScript(url, success) {

    var script     = document.createElement('script');
         script.src = url;

    var head = document.getElementsByTagName('head')[0],
    done = false;

    // Attach handlers for all browsers
    script.onload = script.onreadystatechange = function() {

        if (!done && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) {

        done = true;

            // callback function provided as param
            success();

            script.onload = script.onreadystatechange = null;
            head.removeChild(script);

        };

    };

    head.appendChild(script);

};

getScript('http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js', function() {

    if (typeof jQuery=='undefined') {

        // Super failsafe - still somehow failed...
       alert('Super failsafe - still somehow failed...');

    } else {

        // jQuery loaded! Make sure to use .noConflict just in case
        fancyCode();

        if (thisPageUsingOtherJSLibrary) {

           alert('thisPageUsingOtherJSLibrary');

        } else {

            // Use .noConflict(), then run your jQuery Code
            alert('Use .noConflict(), then run your jQuery Code');
        }

    }

});

} else { // jQuery was already loaded

// Run your jQuery Code
   alert('Run your jQuery Code');

};



</script>
  • Do you see any errors in browser console? – SlackerAmit Feb 18 '16 at 13:58
  • no I don't very strange – Mike Feb 18 '16 at 13:59
  • can you put this script in a file and do a line by line debug in browser? – SlackerAmit Feb 18 '16 at 14:08
  • here is what I did, I figured out that the jQuery document ready function is already called before my page is loaded so I removed the JQuery(document).ready function and just place my code within the script tag and it worked for now. I say this because this happen before and then it stop working. This is very strange behavior. – Mike Feb 18 '16 at 14:36

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.