javascript site root

前端 未结 4 1285
一个人的身影
一个人的身影 2021-02-05 23:36

I have this site that I need to find the root folder / plus the actual folder its works out of.

My problem here is that during development i have the folder with in my l

相关标签:
4条回答
  • 2021-02-05 23:43

    You can map the url localhost/devbuild to localhost/mytestSiteA and use the first url to test your site locally. In your javascript you can always assume the devbuild folder then. That way you don't have to change anything else.

    0 讨论(0)
  • 2021-02-05 23:46

    use relative paths so you don't need to get to the root folder

    this doesn't work on sites with friendly urls with folders in the links

    0 讨论(0)
  • 2021-02-05 23:49

    This is what worked for me after the switch clause.

    var root = location.protocol + '//' + location.host + rootFolder;
    
    0 讨论(0)
  • 2021-02-06 00:01

    try to switch

    switch (document.location.hostname)
    {
            case 'asite.com':
                              var rootFolder = '/devbuild/'; break;
            case 'localhost' :
                              var rootFolder = '/mytestSiteA/'; break;
            default :  // set whatever you want
    }
    

    and then use

    var root = document.location.hostname + rootFolder;
    
    0 讨论(0)
提交回复
热议问题