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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:16:10+00:00 2026-05-18T04:16:10+00:00

I was wondering if eval (or some variant of jQuery’s getScript) can be used

  • 0

I was wondering if eval (or some variant of jQuery’s getScript) can be used to position external javascript in places other than the end of the DOM or at the head. I’ve tried:

var head = document.getElementById("fig"); 

instead of

var head = document.getElementsById("head")[0];

with

var script = document.createElement("script");
script.text = $(".code").val();
head.appendChild(script);

But I can’t seem to get it to work regardless. (The code does work, but Firebug shows the code being replaced both at #fig and at the end of the page, right before the </body> tag.

Basically the JavaScript toolkit I’m using renders things based on where the script tag is located, and I’m trying to dynamically modify the javascript based on user input (hence I can’t really refer to a new external JS file – I’d rather run an eval, which isn’t ideal).

I guess the worst case scenario would be to save the user input into a “new” file using PHP or something and use getScript pointing to that new PHP file, but it seems exceedingly hacky.

Thank you once again!

  • 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-18T04:16:11+00:00Added an answer on May 18, 2026 at 4:16 am

    Does the “JavaScript toolkit” you refer to use document.write or document.writeln to insert output into the page? If so, you could override that function to append the script output into the correct location:

    document.write = function(s) {
        $('#fig').append(s);
    };
    
    document.writeln = function(s) {
        $('#fig').append(s + '\n');
    };
    

    and then load and execute the script using $.getScript.

    Edit: A more robust way of doing it, depending on how the code is added:

    var output = '';
    
    document.write = function(s) {
        output += s;
    };
    
    document.writeln = function(s) {
        output += s + '\n';
    };
    
    $.getScript('URL of script here', function() {
        $('#fig').append(output);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just wondering if some one can help me with some a issue I am
Possible Duplicate: C# eval equivalent? Hi - I was wondering how I can execute
i am wondering if i can do some cleanup routines that will auto grab
My question is regarding JavaScript Closures and the Eval() function. I have some code
Possible Duplicate: When is JavaScript's eval() not evil? I was wondering, besides Eval activates
I'm wondering what sorts of things should be checked when using eval() in PHP
Wondering what the best / good way of doing this would be in jQuery.
Wondering if any of you can help me: I've made a signup modal that
Wondering if anyone can suggest a good file replication tool that will replicate across
I'm wondering how to get a combination name like test1 by using <%# Eval(id)

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.