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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:34:29+00:00 2026-06-05T06:34:29+00:00

So essentially on page load I want to do the following: <script> $(document).ready(function ()

  • 0

So essentially on page load I want to do the following:

<script>
    $(document).ready(function () {
        if (document.location.hostname == "somemachine.poc") {
            var fileref = document.createElement('script')
            fileref.setAttribute("type", "text/javascript")
            fileref.setAttribute("src", "myscript.js")
        }
    });
</script>

In theory and practice is this correct? for some reason I put it on my page and it doesn’t work as expected, and doesn’t even show up in the source of the page.

So what I will end up doing is checking for several domains, dependent on which domain a different src for the .js will load.

UPDATE

The answers below helped me fix the issue, I have a new issue which follows on naturally from this question which can be found here: Losing entire page DOM running javascript

  • 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-05T06:34:30+00:00Added an answer on June 5, 2026 at 6:34 am

    You have to add the script to the document.

    document.body.appendChild(fileref);
    

    It still won’t show up in the source though. The DOM, as modified by JS, is not the source. You would have to use a DOM viewer to see it (e.g. Chrome Developer Tools or Opera Dragonfly).

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

Sidebar

Related Questions

My query is essentially the following: entries=Entry.all().order(-votes).order(-date).filter(votes >, VOTE_FILTER).fetch(PAGE_SIZE+1, page* PAGE_SIZE) I want to
Essentially, on page load, I want a video to be hidden behind an image
I want to load in content from another site (essentially I want to check
I want to write a script that changes page content but within a foreach
I want to use .load to change a div's text based on another page
We have an internal asp.net forms app where one page is essentially a WYSIWYG
Essentially, what I want to do (in DirectX) is to take two partially-transparent images
Essentially I'm wondering if the following can be done in Ruby. So for example:
Essentially what I want to do is to apply additional CSS classes to individual
Sorry For being unclear, what I mean is this. Currently on page load I

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.