Parse URL Used To Include .js File

Discussion in 'JavaScript' started by ellisje007, Sep 28, 2006.

  1. #1
    I have some javascript code on one webapp that is being included on an html in another webapp.

    Server: ServerOne
    Filename: includeme.js
    Contents:

    code:

    alert('inside includeme.js');



    Server: ServerTwo
    Filename: testpage.html
    Contents:

    code:

    <script src="/webapps/ServerOne/scripts/includeme.js">



    The page is rendered when a user types the following into a browser:
    http://ServerName/webapps/ServerTwo/pages/testpage.html

    which includes the contents of "includeme.js".

    I am wondering if it is possible from the javascript inside "includeme.js" to parse the URL that was used to include it

    code:

    <script src="/webapps/ServerOne/scripts/includeme.js">

    and extract the word "ServerOne" from the URL.

    I know this is a strange requirement, and there are a lot of workarounds but I am wondering if the javascript can get ahold of the URL used to include it.

    Thanks,
    Jim
     
    ellisje007, Sep 28, 2006 IP
  2. jrlane7

    jrlane7 Peon

    Messages:
    17
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    var URL = document.location;

    That will tell you page you on.
     
    jrlane7, Sep 28, 2006 IP
  3. ellisje007

    ellisje007 Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    document.location.href

    Actually in this case it won't, because the javascript document.location.href refers to the current window.

    To solve this problem, I was able to give the <script> tag an id and then reference this tag via document.getElementById('scriptTagId') and print out the ".src". attribute of the <script> tag.
     
    ellisje007, Sep 29, 2006 IP