locked
How can I detect which relative path to use? RRS feed

  • Question

  • I'm working on a javascript.

    I have something like:

    self.location="index.htm"

    But depending on where the page is located, for the script to work, it could be also one of the following:

    self.location="../index.htm"
    self.location="../../index.htm"

    I want to put the javasript in a js file and call it from almost all the pages.

    The best would have been to use something like:

    self.location="/index.htm"

    But it doesn't seem to work (at least locally) and I read in the forum that EW doesn't support this kind of absolute path.

    How can I detect which relative path to use? or I must create 3 js files (one for each self.location value possibility) and call the good js file depending on which page I call the script?

    Gaétan
    Musique Progressive Dynamique
    Site consacré au métal progressif
    www.musiqueprog.net
    Wednesday, August 24, 2011 11:53 PM

All replies

  • Ok, the best way I found so far is to declare a variable in the page that tells which directory level is, and then call the js file which use this variable to build the correct value for self.location. Any better idea?


    Gaétan
    Musique Progressive Dynamique
    Site consacré au métal progressif
    www.musiqueprog.net

    Thursday, August 25, 2011 1:14 AM
  • What version of EW are you using?  Did you try /index.htm?
    Thursday, August 25, 2011 1:35 AM
  • What version of EW are you using?  Did you try /index.htm?
    I'm using EW 4 SP2. Like I said, I tried self.location="/index.htm" but it doesn't seem to work.

    Gaétan
    Musique Progressive Dynamique
    Site consacré au métal progressif
    www.musiqueprog.net
    Thursday, August 25, 2011 2:01 AM
  • It should work when on a production server. It may not work in design view.
    Free Expression Web Tutorials
    For an Expression Web forum with without the posting issues try expressionwebforum.com
    Thursday, August 25, 2011 2:18 AM
  • EW4 supports "/index.htm" paths.  I don't have any javascript to test, but try it, previewing the page with the development server, and see if it works.
    Thursday, August 25, 2011 2:22 AM
  • It should work when on a production server. It may not work in design view.
    Free Expression Web Tutorials
    For an Expression Web forum with without the posting issues try expressionwebforum.com

    So I may use the relative path solution because I like to test my site locally before updating it to the server. When using the absolute path "/index.htm" it doesn't work when I browse my website locally (I tried Firefox and IE). I did not tried on a production server.

     


    Gaétan
    Musique Progressive Dynamique
    Site consacré au métal progressif
    www.musiqueprog.net
    Thursday, August 25, 2011 2:26 AM
  • Did you try my suggestion?  Does it work when you set your pages to use the development server for preview?
    Thursday, August 25, 2011 2:32 AM
  • Did you try my suggestion?  Does it work when you set your pages to use the development server for preview?
    Do I need to update the files to my server to try this or it's a feature of the Super Preview (I never really tried the Super Preview...)

    Gaétan
    Musique Progressive Dynamique
    Site consacré au métal progressif
    www.musiqueprog.net
    Thursday, August 25, 2011 2:38 AM
  • This has nothing to do with SuperPreview.  Site Settings:  Preview tab.  It's how you preview your local pages.  Things that need a server (asp.net, PHP) can use the development server.  Check "for all pages", and see if it works.  I'm assuming you are using EW's browser preview.
    Thursday, August 25, 2011 4:02 AM
  • This has nothing to do with SuperPreview.  Site Settings:  Preview tab.  It's how you preview your local pages.  Things that need a server (asp.net, PHP) can use the development server.  Check "for all pages", and see if it works.  I'm assuming you are using EW's browser preview.
    self.location="/index.htm" works when I use for preview the Microsoft Expression Development server for all web pages.

    Gaétan
    Musique Progressive Dynamique
    Site consacré au métal progressif
    www.musiqueprog.net
    Thursday, August 25, 2011 4:32 AM