Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Kap 21 posts 171 karma points
    Oct 23, 2024 @ 14:20
    Kap
    0

    Waiting for Smidge to load JS before running inline js

    Hi All,

    I am having issues where the code I am porting to Umbraco 13 uses both external and inline javascript. Most of the time this is fine, except sometimes, it appears that the inline code is attempting to run before the external javascript has been loaded by smidge.

    eg I have

    @{
    smidgeHelper.RequiresJs("~/scripts/jquery-3.5.1.min.js");
    }
    <script>
    $("#tagname").on('change', function(){
    alert("Blah");
    });
    </script>
    

    When the page loads, I get errors in the console indicating that $ is undefined, because the inline code runs before the external javascript is loaded.

    Is there anyway I can delay the running of the inline javascript until after smidge has loaded the external files?

    Thanks

    Kap.

  • Kap 21 posts 171 karma points
    Oct 23, 2024 @ 16:50
    Kap
    0

    I have managed to work around the issue using window.onload

    @{
    smidgeHelper.RequiresJs("~/scripts/jquery-3.5.1.min.js");
    }
    <script>
    window.onload = function(){
    $("#tagname").on('change', function(){
    alert("Blah");
    });
    }
    </script>
    

    which appears to work, but it seems a bit messy. Is there a better way to do this?

    Thanks agian,

    Kap.

Please Sign in or register to post replies

Write your reply to:

Draft