SitePoint Sponsor |
|
User Tag List
Results 1 to 5 of 5
-
Dec 16, 2003, 09:46 #1
- Join Date
- Apr 2002
- Location
- Tucson, AZ
- Posts
- 176
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Can a function on external js page tell which page is calling it
I have a function on an external js page that I'm calling from 4 different html pages. Is there anyway I can tell which page is calling on the function? I need the function to act a little different depending on which page calls it.
Anthony
-
Dec 16, 2003, 11:12 #2
- Join Date
- Dec 2002
- Location
- Alabama, USA
- Posts
- 2,560
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Two quick ideas:
1) The caller could pass a code to the function which indicates the current page name.
2) The function can parse "window.location.pathname" to get the current page name.Cross-Browser.com, Home of the X Library
-
Dec 17, 2003, 11:46 #3
- Join Date
- Jan 2003
- Posts
- 781
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
OR on each of your page set a global varialbe to some number, then in the function check the value of that variable.
OR pass this number as parameter to the function.
-
Dec 17, 2003, 12:15 #4
- Join Date
- Dec 2002
- Location
- Alabama, USA
- Posts
- 2,560
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
OR on each of your page set a global varialbe to some number, then in the function check the value of that variableCross-Browser.com, Home of the X Library
-
Dec 20, 2003, 19:36 #5
- Join Date
- Sep 2002
- Location
- Bournemouth, South UK
- Posts
- 1,551
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
Code:loc=self.location.href if(loc.indexOf(".html")<0) loc+="index.html" loc=loc.split("/") file=loc[loc.length-1] folder=loc[loc.length-2] domain=loc[loc.length-3]
I also split my domain from the location as well......
Code:loc=loc.split("mysite.com")[1]
Code:loc=self.location.href loc=loc.split("+")[0]; //escapes Googles caching loc=loc.split("?")[0]; //escapes variables loc=loc.split("#")[0]; //escapes anchors if(loc.indexOf(".html")<0) loc+="index.html" loc=loc.split("/") file=loc[loc.length-1] folder=loc[loc.length-2] domain=loc[loc.length-3]
Last edited by Markdidj; Dec 21, 2003 at 09:23.
LiveScript: Putting the "Live" Back into JavaScript
if live output_as_javascript else output_as_html end if
Bookmarks