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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:58:45+00:00 2026-06-12T22:58:45+00:00

I have a script tag which calls a remote JavaScript snippet through src, and

  • 0

I have a script tag which calls a remote JavaScript snippet through src, and writes it on the page, thus rendering a banner in the process.

I’m looking for a way to call the script, or insert the script via JavaScript. Right now it looks like this:

<div id="<?php print $banner_id; ?>" class="banner-responsive <?php print $breakpoints; ?>">
  <script src="<?php print $url; ?>"></script>
</div>

This is the preferred method supplied by the banner vendor. I’m looking for a way to implement it more like this:

<div class="banner">
  <div id="<?php print $banner_id; ?>">
    <script type="text/javascript">
      function banner_load(){
        var s = document.createElement('script');
        s.type = 'text/javascript';
        s.src = '<?php print $url; ?>';
        var x = document.getElementById('<?php print $banner_id; ?>');
        x.parentNode.appendChild(s);
      }
      if (window.attachEvent)
        window.attachEvent('onload', banner_load);
      else
        window.addEventListener('load', banner_load, false);
    </script>
  </div>
</div>

This sort of works. It inserts the script tag, and calls the remote URL, but it does not execute the JS snippet received like it does in example 1, and because of that the banners do not appear. Is there a way for me to execute the script src at will?

What the src response could look like:

document.write("<a target='_blank' href='http://domain/?options'><img src='http://domain/whateever-930x180px.jpg' alt='Click here' /></a>");

I want to do this, so I can switch banners at specific moments, based on pre-defined break points. How would you go about this? Any thoughts?


Update: I don’t have any control over the output. It’s an external banner supplier. I take it that this is impossible?

  • 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-12T22:58:46+00:00Added an answer on June 12, 2026 at 10:58 pm

    You cannot dynamically load javascript that uses document.write() and get the result you want.

    Dynamically loaded javascript runs AFTER the DOM has been loaded. When document.write() is used after the DOM has been loaded, it clears the entire document and starts a new empty document. As such, it will not do what you want.

    If you want to dynamically load the Javascript, then you will need to use DOM manipulations (e.g. document.createElement() and elem.appendChild()) to insert your banner into the existing DOM and not use document.write(). document.write() is only useful for this type of problem when it is done inline with sequentially loaded javascript either inline or via <script> tags in the markup (not via dynamically loaded javascript).

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

Sidebar

Related Questions

I have defined in my head tag a function <script> functionX(a,b,c) ....</script> which calls
I have script that reads remote file content and writes it to local server.
I have a div tag which is filled with script via an ajax call,
I have a script which calls an external API using curl. This script worked
I have an mxml file with a bunch of functions in the script tag,
To start, I know that I have to have the </script> tag, and there
I have script which allows to display Bing search results. I can call for
i have a script which is for virtual keyboard, i am facing some problem
I have implemented an XMLHttpRequest() call to a standalone html page which simply has
Scenario: I have a Javascript-generated web page that someone else wrote a long time

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.