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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:26:33+00:00 2026-05-15T02:26:33+00:00

I include myscript.js in the file http://site1.com/index.html like this: <script src=http://site2.com/myscript.js></script> Inside myscript.js, I

  • 0

I include myscript.js in the file http://site1.com/index.html like this:

<script src=http://site2.com/myscript.js></script>

Inside “myscript.js”, I want to get access to the URL “http://site2.com/myscript.js“. I’d like to have something like this:

function getScriptURL() {
    // something here
    return s
}

alert(getScriptURL());

Which would alert “http://site2.com/myscript.js” if called from the index.html mentioned above.

  • 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-15T02:26:33+00:00Added an answer on May 15, 2026 at 2:26 am

    From http://feather.elektrum.org/book/src.html:

    var scripts = document.getElementsByTagName('script');
    var index = scripts.length - 1;
    var myScript = scripts[index];
    

    The variable myScript now has the script dom element. You can get the src url by using myScript.src.

    Note that this needs to execute as part of the initial evaluation of the script. If you want to not pollute the Javascript namespace you can do something like:

    var getScriptURL = (function() {
        var scripts = document.getElementsByTagName('script');
        var index = scripts.length - 1;
        var myScript = scripts[index];
        return function() { return myScript.src; };
    })();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've succesfully implemented this script: http://blueimp.github.com/jQuery-File-Upload/ (it uses jquery file upload ) The problem
If I want to insert the output of a script into an HTML file
This is my pagination script, which I've been working on: http://pastebin.com/4mpjdWKD This is the
So I have a Python script: myscript.py I am executing it like this: python
Hi I am trying to include a perl script within my shtml file. Unfortunately
Given the following MSBuild project file: <Project ToolsVersion=3.5 DefaultTargets=DoA xmlns=http://schemas.microsoft.com/developer/msbuild/2003> <ItemGroup> <A Include=1.txt> <Define>B=2;C=3</Define>
The SRC and HREF attributes are used to include some external entities like an
I am investigating a way to include a JavaScript file within some script tags.
In my script, I set the include path (so another part of the application
I'm using 'Simple HTML Dom' to scrape the HN Front Page (news.ycombinator.com), which works

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.