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 7080647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:49:16+00:00 2026-05-28T06:49:16+00:00

I am trying to make a plugging using JS. I have the following code

  • 0

I am trying to make a plugging using JS.
I have the following code :

var fileref = document.createElement('script');
fileref.src = "js/index.js";
document.documentElement.appendChild(fileref);

I can verify that the code loads across domain however it doesn’t always execute. Even if I set it before </head>

Sometimes it does but sometimes it just doesn’t. Any ideas on what I could be doing wrong?

  • 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-28T06:49:16+00:00Added an answer on May 28, 2026 at 6:49 am

    The JavaScript is sometimes running before the document.documentElement exists. So when it goes to append the new script element, it fails. The inconsistency (“sometimes it does but sometimes it just doesn’t”) is due to the page rendering at ever-so-slightly different speeds.

    Update:

    Put this in your <head>:

    <script type="text/javascript">
        (function () {
            var scrpt = document.createElement('script');
            scrpt.type = 'text/javascript';
            scrpt.async = true;
            scrpt.src = 'js/index.js';
            var s = document.getElementsByTagName('script')[0];
            s.parentNode.insertBefore(scrpt, s);
        })();
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to make a MySQL-based application support MS SQL, I ran into the following
Trying to make my project using storyboard. I changed my info.plist and added entry
Trying to make a Grid Like this using java and I'm assuming a 2d
Im trying to make a recreation of MSWord using WPF RichTextBox and Toolbar, so
In trying to make my Javascript unobtrusive, I'm using onLoad s to add functionality
Trying to make a simple jquery drop down here, here's my code so far:
Im trying to make an app that converts distance/area/volume using spinners as a unit
I'm trying make some stuff in jQuery using ASP.NET. But the ID from runat=server
I'm trying make this code which is from a Dictionary of Arrays (CODE) from
Trying to make this script go random. I tried variations of this string $banner_no

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.