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

  • SEARCH
  • Home
  • 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 8708271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:05:26+00:00 2026-06-13T04:05:26+00:00

I found a little javascript snippet for including javascripts only if they was not

  • 0

I found a little javascript snippet for including javascripts only if they was not included before.

That is working with my own scripts, but with two third-party libraries it’s not working and I really don’t know why.

    var included_files = new Array();
    function include_once(script_filename) {
        if (!in_array(script_filename, included_files)) {
            included_files[included_files.length] = script_filename;
            include_dom(script_filename);
        }
    }
    function in_array(needle, haystack) {
        for (var i = 0; i < haystack.length; i++) {
            if (haystack[i] == needle) {
                return true;
            }
        }
        return false;
    }
    function include_dom(script_filename) {
        var html_doc = document.getElementsByTagName('head').item(0);
        var js = document.createElement('script');
        js.setAttribute('language', 'javascript');
        js.setAttribute('type', 'text/javascript');
        js.setAttribute('src', script_filename);
        html_doc.appendChild(js);
        return false;
    }

function loaded() {
    include_once("shared/scripts/jquery.min.js");
    include_once("shared/scripts/iscroll.js");

    $(document).ready(function () {
        alert("hello");
    });
}

error: $ is not defined.
If I import jQuery the regular way its working and it says “iScroll” is not defined (because I’m using it later).

Any ideas?

  • 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-06-13T04:05:27+00:00Added an answer on June 13, 2026 at 4:05 am

    Did someone say callback?

    function include_once(script_filename, callback) {
            if (!in_array(script_filename, included_files)) {
                included_files[included_files.length] = script_filename;
                include_dom(script_filename, callback);
            }
        }
    
    function include_dom(script_filename, callback) {
        var html_doc = document.getElementsByTagName('head').item(0);
        var js = document.createElement('script');
        js.setAttribute('language', 'javascript');
        js.setAttribute('type', 'text/javascript');
        js.setAttribute('src', script_filename);
        if(callback && callback != 'undefined'){
            js.onload =  callback;
            js.onreadystatechange = function() {
                if (this.readyState == 'complete') callback();
            }
        }
        html_doc.appendChild(js);
        return false;
    }
    
    function loaded() {
        include_once("shared/scripts/jquery.min.js", function(){
            $(document).ready(function () {
                alert("hello");
            });
        });
        include_once("shared/scripts/iscroll.js");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

found this little code snippet that seems to do what i want, but im
I've found a little tutorial that would be useful for my game: http://blog.mellenthin.de/archives/2012/02/13/an-one-finger-rotation-gesture-recognizer/ But
I poked around StackOverflow and Google, but I found articles little too older that
Found a piece of code today, that I find a little smelly... TMyObject.LoadFromFile(const filename:
I've started working a little bit with lift+scala+mongorecord but I found a small annoyance
I wrote a little javascript function that checks for a cookie when onFocus is
I have a trivial little game I wrote in javascript that creates a wave
I'm programming an iPhone app that uses a little bit of javascript code for
This Javascript that I found here adds a method parseURL() to the string object
I know very little about javascript so I'm not exactly sure what I'm doing.

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.