| 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: 15357
|
|
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: 56192
|
|
|
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?
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About 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!
|
 |
 |
|
|
subject: Find Location Of .js File
|
|
|