javascript site root

前端 未结 4 1352
一个人的身影
一个人的身影 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-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;
    

提交回复
热议问题