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

The Archive Base Latest Questions

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

Ok, I feel a bit dumb having to ask this. There are any number

  • 0

Ok, I feel a bit dumb having to ask this. There are any number of hits on similar questions, but I can’t seem to get it right. If I modify the DOM via jQuery/Ajax, when is a loaded script actually parsed/executed?

The code below works on F/F, but not on Chrome or Opera. ‘Working’ means that it executes ‘do_init()’ without error. The loaded script (actually an svg file; ‘file.svg’) defines a number of vars which are required by ‘do_init()’ (which is in the ‘static’ script). These vars are visible to F/F, but not to Chrome or Opera (“variable xxx is undefined”). The file/script is correctly loaded into the DOM in all 3 cases, and contains an <svg>, with a <script> inside it.

I can get this to work (the svg displays) in Opera (or break in F/F) by re-arranging code, but not in Chrome. Using .success and .complete makes no difference.

Thanks.

<head>
...
<script type="text/javascript" src="do_init.js"></script>          
<script type="text/javascript"><![CDATA[
jQuery(document).ready(function() {
   ...
   $("#submit").click(function(e){
      e.preventDefault();
      var jqxhr =
         $("#svg").html(ajax_load).load("file.svg", function(response, status, xhr) {
            if(status == "error") {
               var msg = "Error: ";
               $("#error").html(msg + xhr.status + " " + xhr.statusText);
            } else {
               do_init(); // Ok in F/F, not in Chrome/Opera
            }
      });
   });
});
]]></script>
</head>
<body>
<button id="submit" type="button">Click Me!</button>
<div id="svg"></div>
</body>

EDIT 1

It turns out that they’re never executed – at least in IE9, FF8, Chrome, Opera, and Safari. They are executed in FF7. I’ve just written a minimal test page which does an Ajax load of a script which is just an alert. This only shows an alert in FF7. I’ve also tried the script wrapped in an <svg>, which makes no difference.

  • 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-26T19:01:34+00:00Added an answer on May 26, 2026 at 7:01 pm

    This is part of the reason why it is recommended that you locate javascript at the end of the document, at the end of the body.

    Generally, javascript is executed as it is encountered; if you put it at the top of the document, it will run early in the load process, late if located at the end. However, when using a library’s “onLoad” or “domReady” functionality, you’re deferring execution until a later time.

    See the jQuery docs for more information: http://api.jquery.com/ready/

    While JavaScript provides the load event for executing code when a page is rendered, this event does not get triggered until all assets such as images have been completely received. In most cases, the script can be run as soon as the DOM hierarchy has been fully constructed. The handler passed to .ready() is guaranteed to be executed after the DOM is ready, so this is usually the best place to attach all other event handlers and run other jQuery code. When using scripts that rely on the value of CSS style properties, it’s important to reference external stylesheets or embed style elements before referencing the scripts.

    EDIT
    I misread the details of your question. A dynamically loaded script is parsed immediately, but the onLoad event may (or may not!) be fired in accordance with the HTTP transport aspect of the loaded script rather than upon the interpretation of the loaded script. Usually, this is fine (though some browsers don’t reliably fire the event – IE, looking at you), but the timing you’re after is not when the script has been fetched, but when it is actually parsed and active. These should be within milliseconds, usually rendering the difference meaningless.

    There are some varying takes on solving issues with this technique, some of which are discussed here and here – none seem to specifically mention Chrome as a source of troubles though. That said, the suggested approach of polling for the included script (via a timeout) seems to be the least failure-prone of the suggestions, though it is also the solution I like least.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, I feel a bit foolish for having to ask this but I guess
I feel a bit embarrassed asking this questions, but how the heck can I
I feel a bit silly for this one, but is there a more elegant
I feel a bit stupid but this is not working (and I expected it
I feel a little bit silly asking this, but I haven't been able to
I feel like this may be a dumb question, but it's late and my
I feel a bit stupid as i can't find the answer to this question,
I feel a bit embarrassed for asking this but here goes: I'm using Excel
This is my first question to stackoverflow, and I feel a bit daft having
As a Rails developer I feel a bit stupid asking this question but hopefully

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.