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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T02:18:40+00:00 2026-05-21T02:18:40+00:00

I am creating a web page that utilizes the YouTube API. I want to

  • 0

I am creating a web page that utilizes the YouTube API. I want to be able to fire off an AJAX style call to the YouTube API every time the user takes certain actions and update in-page elements with the results of the calls. YouTube’s documentation recommends using Javascript injection to get around the cross domain permission issues that would be involved with making AJAX calls to a foreign domain (gdata.youtube.com) from my web page. For example:

<script 
    type="text/javascript" 
    src="http://gdata.youtube.com/feeds/users/GoogleDevelopers/uploads?alt=json-in-script&format=5&callback=showMyVideos">
</script>

This snippet placed inside the HTML BODY makes a video feed request from the “GoogleDevelopers” channel with the “callback” parameter causing a call to showMyVideos() when the call returns. showMyVideos(), not shown here and arbitrarily named, uses DOM calls to update a named DIV with the results of the call.

I want to do the same operation except dynamically instead of statically like shown above. For example, I have seen code like this:

var s = document.createElement('script');
    s.type = "text/javascript";
    s.src = "http://gdata.youtube.com/feeds/users/GoogleDevelopers/uploads?alt=json-in-script&format=5&callback=showMyVideos"
    var head = document.getElementsByTagName('head')[0];
    head.appendChild(s);

My concern is if I use this approach, since I will be making many AJAX calls, I will accumulate more and more dynamically generated Javascript DOM elements in the web page DOM tree, and I worry what consequences that might have to the browser or anything else.

Is there a way to do Javascript injection in this style without cluttering up the HEAD element lots of Javascript elements? A concise code sample would be appreciated.

— roschler

  • 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-21T02:18:40+00:00Added an answer on May 21, 2026 at 2:18 am

    Well, not that hard, after you’ve gotten your data you clean up by removing the script element.

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

Sidebar

Related Questions

I am creating a web page, where I have an image that I want
I'm creating a form on a web page, but I want that form to
I am creating a table to display on a web page and that table
I am creating a web-page/website that integrates all my accounts into one spectrum, as
I'm creating a web page that allows users to select a value using the
I am creating a web page that includes several HTML-templates that may contain IDs.
I'm creating a web page that search users in the database. When I'm typing
I am creating a Web page that contains the following code. <script> function changeColor(c)
I use Asp.NET Mvc 3 for creating web page and so I detect that
In summary : I have an ASP.NET web page that causes an AJAX postback

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.