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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:33:20+00:00 2026-06-04T10:33:20+00:00

I have a web application that essentially has header, footer and body views. I’m

  • 0

I have a web application that essentially has header, footer and body views. I’m working on ajaxifying the website, using the history.js library and HTML5 pushstate, but one of the problems I’m experiencing is getting embedded javascript to run when the javascript is inserted into the DOM.

Pretty much all my javascript is wrapped in jQuery(function(){ … }) (document on-ready loader)

Does anyone know a good strategy for dealing with this? Thanks!

  • 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-04T10:33:21+00:00Added an answer on June 4, 2026 at 10:33 am

    If I understand you, your “page” is just a container for HTML you’re loading dynamically. Within that HTML you have JavaScript script blocks that currently do not execute. Is that correct? Are they in page scripts or links to new script files?

    In any case, I think this answers your question: How do you execute a dynamically loaded JavaScript block?

    My own thoughts:

    Unless your container is incredibly generic, and so cannot know what JavaScript you might need, the simplest approach is probably to just manually attach all of your JavaScript to your container page, so that it loads with the container, perhaps minified and concatenated into a single file.

    If you need to load your scripts dynamically, but you know what they are, you can do so with jQuery using .getScript() or .ajax(). I thought this page spelled things out nicely, http://www.electrictoolbox.com/jquery-dynamically-load-javascript-file/ .

    Similarly, if you don’t know what scripts you need until after you grab your html block, you could probably parse the html for script links and attach them manually via new script elements added to the page. As an example, the script below adds jQuery to the page if it does not already exist.

    (function () {
    
        if (typeof(jQuery) == "undefined") {
            var headID = document.getElementsByTagName("head")[0];         
            var newScript = document.createElement('script');
            newScript.type = 'text/javascript';
            newScript.id = 'myjQuery';
            newScript.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js';
            headID.appendChild(newScript);
        }
    
        window.addEventListener('load', function (e)  {
    
            //make jQuery calls here.
    
        }, false);
    
    })();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web application that has a page that loads the content from
I have a web application that is using both jQuery 1.2.6 and YUI 2.6.0
We have an iPhone application that is essentially a web site encapsulated in an
I have this ajax web application I am developing that essentially calls the google
I have a C# application that has links to certain features on a web
I have a web application that runs fine under IIS5 or IIS6. I just
I have a web application that uses TONS of javascript, and as usual, there
I have a web application that uses AzMan authorization to grant different functionality to
I have a web application that uses two databases. DB1 Users perform their CRUD
I have a web application that functions as a dashboard, allowing a user to

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.