javascriptiframereferenceerrordynamic-script-loading

I have loading iframe by adding scripts dynamically. But getting a Reference error as $ is not defined


I'm calling the function after adding the jquery script. but still, I'm getting a Reference error

<script>
    window.onload = function(){
        AddScript("https://cdn.syncfusion.com/js/assets/external/jquery-1.11.3.min.js");

        $(function () { //Error throws while executing this line
            //My code here
        });
    }

    function AddScript(source)
   {
      var head= document.getElementsByTagName('head')[0];
      var script= document.createElement('script');
      script.src= source;
      head.appendChild(script);
   }
</script>

Solution

  • I thought this is not an issue. this should be handle in sample level since you have append the external script directly without waiting to load it from cdn.

    https://humanwhocodes.com/blog/2009/07/28/the-best-way-to-load-external-javascript/