calling functions that contain pathnames

Results 1 to 5 of 5

Thread: calling functions that contain pathnames

  1. #1
    Talula Guest

    Default calling functions that contain pathnames

    This is actually a JavaScript question, I think, but it is within an ASP file that I am having trouble.<BR><BR>I have a function that will redirect a user to a page if I need the user to fill out a form they forgot to submit. The function is in an included .js file in the folder "../scripts/" <BR><BR>In the function (within the .js file), the redirect path is:<BR><BR>"../hr/timeoff.asp"<BR><BR>When I call the function from a script in a "peer" directory, say, "../emp/timesheet.asp" it works great! But when I call it from a sub-directory of a peer, "../emp/calc/vacation.asp" I get an error.<BR><BR>The error is "The page cannot be found." This is because the page it is looking for is "../emp/hr/timeoff.asp" when it should be going to "../hr/timeoff.asp."<BR><BR>Is there an easy way get the function to redirect the user to the correct pathname based on from where I am trying to call the function? <BR><BR>I hope this was clear.<BR>Let me know if you need more info.<BR><BR>Thanks in advance :o)

  2. #2
    Join Date
    Dec 1969

    Default RE: calling functions that contain pathnames

    the reason is <BR><BR>when u r calling the function from "../emp/timesheet.asp"<BR>to go to "../hr/timeoff.asp", means u r asking it to go one level up from the directory u r in (which is emp/), so it is working.(i guess the /hr is residing one level above emp/)<BR><BR>but when u r calling it from /emp/calc/vacation.asp, u r in calc directory, so it is going one level up to search in emp/ directory.You should set the path relative to the directory u are in, not to any one directory.<BR><BR>change ur redirection path accordingly that suits all levels

  3. #3
    Talula Guest

    Default CHALLENGE: Anyone else understand my problem?

    I wasn&#039t asking for a reason. I know the reason. I am just looking for input on how to fix it. Pseudo-code would be great :o)<BR><BR>I am asking if there is a way to maybe "sense" what directory level I am in and modify the redirect so that it sends the user to the right script. Maybe add an extra "../" in front of the path name for every sub-level.<BR><BR>I cannot redirect the user to "d:/intranet/hr/timeoff.asp because<BR>I would have to modify the script everytime I moved it from one of the development servers to the live server. (The live server has the scripts on the G drive in the folder g:/isd/html/intranet/ and the dev servers are complete different).<BR>I can&#039t do it like this: because the development servers are like this: and<BR><BR>Maybe getting the URL string and parsing out the directory levels... then reconstruct the pathname?<BR><BR><BR><BR>

  4. #4
    tango Guest

    Default RE: calling functions that contain pathnames

    How about trying ServerVariables(SCRIPT_NAME) to get the directory name and moving from there?<BR><BR><BR>

  5. #5
    Talula Guest

    Default Thanks! Here's my solution.

    This part goes toward the top of my .js file:<BR><BR> prefix = &#039&#039<BR> loc = &#039&#039 + location.href<BR> paths = loc.substring(7).split(&#039/&#039)<BR> // subtract 2 from the length to account for the domain<BR> // name and then the file name<BR> for (i=0, n=paths.length-2; i&#060;n; i++)<BR> prefix += &#039../&#039<BR><BR><BR><BR>Then in my function, my path looks like this:<BR>strURL = prefix +&#039hr/timeoff.asp&#039<BR><BR><BR>So, if I am in the root directory, my path is:<BR>hr/timeoff.asp<BR><BR>If I am in a child directory of the root, it looks like this:<BR>../hr/timeoff.asp<BR><BR>Then...<BR>../../hr/timeoff.asp<BR><BR>WOO HOO!<BR>

Posting Permissions

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