aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Find Location Of .js File Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Find Location Of .js File" Watch "Find Location Of .js File" New topic
Author

Find Location Of .js File

James Ellis
Ranch Hand

Joined: Oct 14, 2004
Posts: 205
I have some javascript code on one webapp that is being included on an html in another webapp.

Server: ServerOne
Filename: includeme.js
Contents:


Server: ServerTwo
Filename: testpage.html
Contents:


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 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
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
not sure if it would work, but you might be able to give the script tag an id and use document.getElementById("foo") and read the src and see if it gives you the info you need. Not positive it will work.

Eric
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61654
    
  67

That type of implicit branching is really icky and can only lead to trouble. If you need to exhibit different behaviors, why not pass a parameter that tells the code how to behave?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
James Ellis
Ranch Hand

Joined: Oct 14, 2004
Posts: 205
I was able to give the script tag an id <script id="scriptTag" src="http://blah.com"> then grab the src attribute of the script tag via:



and then parse the string from there.

Thanks Everyone!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Find Location Of .js File