SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2002
    Location
    Italy
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    referencing imported js files

    hi,
    i have a question which has been stumping me for quite a while now and i hope somebody can help me here!

    when we import a js file in a page using the location.href command will give us the url of the page calling the js file. is there a command which will reference the url of the js file itself.

    in other words:
    HTML Code:
    <html>
    <head>
    <script type="text/javascript" src="http://url_to_js.js"></script>
    </head>
    <body>
    ...
    </body>
    </html>
    if we call the location.href command from within the js file we will get the url of the page calling the js file. what command will return instead http://url_to_js.js?


    thanks for your help,
    frodo

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,290
    Mentioned
    198 Post(s)
    Tagged
    3 Thread(s)

    location

    In other words, how can the code determine it's (source file) location within the directory structure?

  3. #3
    SitePoint Enthusiast
    Join Date
    Mar 2002
    Location
    Italy
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    exactly

  4. #4
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am also not sure about that. Last time i also needed that but could find the solution. But i had used a trick to includ a js file within another.
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  5. #5
    SitePoint Guru
    Join Date
    Apr 2006
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The src is an attribute of the script element-
    get the script element via the document.getElementsByTagName('script') node list.
    If there is only 1 script:
    srcString=document.getElementsByTagName('script')[0].src;


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •