Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6651209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:59:01+00:00 2026-05-26T00:59:01+00:00

I need to create a simple javascript embed type thing where the user adds

  • 0

I need to create a simple javascript embed type thing where the user adds a small amount of javascript to their site and my script does the rest.

This is the sort of thing I would like to see on the user site:

Included once:

<script type="text/javascript" src="path/to/doEverythingScript.js"></script>

And this in the HTML:

<div id="target-div">    
    <script type="text/javascript">
        doThis(1714581, "#target-div");
    </script> 
</div>

I would also need to be able to have multiple versions running on the same page.

The id (eg: 1714581) is passed to my function along with my target div.

This issue is I need to have the one script load all the dependancies:

eg:

path/to/style1.css
path/to/style2.css
path/to/style3.css
path/to/jquery.js
path/to/script1.js
path/to/script2.js
path/to/script3.js
path/to/script4.js

And once they are all loaded I would then be able to run my function.

If my function ran before they all loaded It naturally wouldn’t work.

I tried using LazyLoad and LAB but couldn’t work out how to have one JS file sort all this out with only one linkied script and a small function on the page.

What I have writen so far doesnt work becuas the function tries to run before the dependecies are loaded.

Any help with this issue is much appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T00:59:02+00:00Added an answer on May 26, 2026 at 12:59 am

    Let this be your loaded script (configure the first block to meet your wishes). On request of the OP, I’ve also added a queue function.

    Note: Add _REQUIRED_ instead of an external resource, if you want to delay loading additional scripts until the previously requests has been finished.

    //@author Rob W. See: http://stackoverflow.com/q/7698018#7698219
    
    //The "real" doThis. You can define any number of arguments.
    function _$doThis(a,b){
    
    }
    
    var rw$loader_queue = []; //Unique name, to prevent messing with the code
    function doThis(){rw$loader_queue.push(arguments)}
    function _doThisAll(){
        for(var i=0,len=rw$loader_queue.length; i<len; i++){
             //Function.apply: First argument = context (default window)
             // second argument = array of arguments
            _$doThis.apply(null, rw$loader_queue.shift());
        }
    }
    (function(){//Anonymous function = no variable leaking
        //Append the scripts.styles to the head, if existent. Otherwise, try body
        var main = document.getElementsByTagName("head")[0] || document.body;
        var _REQUIRED_ = ((new Date).getTime()*(new Date).getTime()||Math.random()).toString(36);
        /***CONFIGURATION**/
        var nocache = false; //false = allow caching
    
        /*Usage: initLoad("type",
                          (multidimensional) array | string,
                           optional function: called when initLoad finishes
                         ) */
    
        initLoad("style", [
          //'sc-player-widget/css/themes/dark-hive/jquery-ui-1.8.16.custom.css',
            'sc-player-widget/css/themes/base/jquery.ui.all.css',
            'sc-player-widget/css/themes/base/jquery.ui.selectmenu.css', 
            'sc-player-widget/css/sc-player.css',
            'sc-player-widget/colorbox/colorbox.css'
        ]);
        initLoad("script", [
            'http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js',
             _REQUIRED_,
            'sc-player-widget/js/ui/jquery.ui.core.js', 
            'sc-player-widget/js/ui/jquery.ui.widget.js', 
            'sc-player-widget/js/ui/jquery.ui.position.js',
            'sc-player-widget/js/ui/jquery.ui.selectmenu.js', 
            'sc-player-widget/js/ui/jquery.ui.button.js',
            'sc-player-widget/colorbox/jquery.colorbox-min.js',
        ], _doThisAll);
    
        /*END OF CONFIG*/
    
        function initLoad(type, source, ready){
            var currentSources = source instanceof Array ? source : [source];
            var beforeRequire = 0;
            var paused = false;
            var hasFinished = false;
            var num_resources = 0;
            var load_success = 0;
            next(); //Start walking through the requested resource;
    
            return;
            function next(){
                if(!currentSources.length){ //End of sources
                    if(typeof ready == "string") ready = window[ready];
                    if(typeof ready == "function" && !hasFinished) (hasFinished=true) && ready();
                    return;
                }
                var current = currentSources.shift();
                if(current === _REQUIRED_){
                    if(!currentSources.length) return next();
                    paused = true;
                    return;
                }
                beforeRequire++;
                num_resources++;
                loadResource(type, current, finished);
                if(currentSources.length) next();
                // If length == 0, wait until the resources have finished loading
            }
            function finished(){
                load_success++;
                if(!--beforeRequire && paused) next();
                else if(num_resources == load_success && !currentSources.length) next();
                //If end of queue, next() = ready()
            }
        }
        function loadResource(type, src, finish){
            if(nocache) src += "?"+(new Date).getTime();
            var s = document.createElement(type=="style"?"link":type);
            var executed = false;
            function oncomplete(){
                if(executed) return;
                executed = true;
                s.onreadystatechange = s.onload = null;
                finish();
            }
            s.onreadystatechange = function(){
                if(this.readyState == "loaded" || this.readyState == "complete") oncomplete();
            }
            s.onload = oncomplete;
            if(type == "style"){
                s.type = "text/css";
                s.rel = "stylesheet";
                s.href = src;
            } else s.src = src;
            main.appendChild(s);
        }
    })();
    

    In your HTML source:

    <script src="path/to/doEverythingScript.js"></script>
    ...
    <script>
        doThis(1714581, "#target-div");
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to create simple reusable javascript object publishing several methods and parameterized constructor.
I need to create a simple editor using a RichTextBox control in a windows
i have very simple problem. I need to create model, that represent element of
I need a very simple and clear example of how to create an OCX
For the purpose of the question I need to create a simple fictitious scenario.
This is for a Java script course that Im taking... I need to create
I'm trying to create a fairly simple piece of JavaScript that displays a random
I need to create a simple IE addon, and trying to figure out how
How can I create a widget from the Javascript. For example I need to
I am messing around with some Javascript game development, trying to create a simple

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.