Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Find Location Of .js File

 
James Ellis
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64843
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
James Ellis
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic