SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot ant1832's Avatar
    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

  2. #2
    I'll take mine raw silver trophy MikeFoster's Avatar
    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.

  3. #3
    Learning...
    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.

  4. #4
    I'll take mine raw silver trophy MikeFoster's Avatar
    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 variable
    Good idea!

  5. #5
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    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]
    by using this method you have choices of camparing file, folder and domain as well as loc[0], loc[1],loc[2]

    I also split my domain from the location as well......
    Code:
    loc=loc.split("mysite.com")[1]
    added: Google's cache of your site has a "+" in the location, you will need to split that from it as well as any location variabls and anchors you may use.....
    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

Posting Permissions

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