javascript site root

风流意气都作罢 提交于 2019-12-03 02:39:12

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;

This is what worked for me after the switch clause.

var root = location.protocol + '//' + location.host + rootFolder;

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.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!