javascript网站root [英] javascript site root

查看:97
本文介绍了javascript网站root的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个网站,我需要找到根文件夹/加上其工作的实际文件夹。

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 local server that in turn is with in its own folder:

然后在线我将开发站点放在一个文件夹中,所以它可以在之前进行测试现场制作等。

Then online I then have the development site within a folder, so it can all be tested before the live production etc.

本地服务器:
localhost / mytestSiteA /...

LOCAL SERVER: localhost/mytestSiteA/...

LIVE服务器测试文件夹:
www.asite.com/devbuild /....

LIVE SERVER TEST FOLDER: www.asite.com/devbuild/....

现在我可以通过

    document.location.hostname 

但是我需要在此之后添加文件夹名称,这样我就可以在开发模式下加载内容等。

But i need then to add the folder name after this so that I can load in content etc when in developement mode.

LOCAL SERVER

LOCAL SERVER

 document.location.hostname + '/mytestSiteA/'

LIVE TEST SITE

LIVE TEST SITE

 document.location.hostname + '/devbuild/'

但我的问题是,是否有一种简单的方法可以获得这个内部文件夹而不是设置确定是否在本地开发,实时开发或实时模式中确定变量,这可能是一种痛苦,并且可以动态获取当前内部文件夹,而不是手动更改等,以便我可以正确添加路径。

But my issue is, is there an easy way to gain this inner folder rather than setting up variables determined on whether in local dev, live dev or live mode, as can be a pain, and would be nice to gain the current inner folder dynamically rather that manually changing etc so that I can add my paths correctly.

也有帮助,好像我有一个文件夹,也在js脚本中加载,它可以获得它的完整路径。

Also would help as if I have a folder within this that also loads in js script it can obtain its full path.

本地服务器:
localhost / mytestSiteA / subsection /...

LOCAL SERVER: localhost/mytestSiteA/subsection/...

实时服务器测试文件夹:
www.asite.com/devbuild/subsection/ ...

LIVE SERVER TEST FOLDER: www.asite.com/devbuild/subsection/...

我希望我能让它变得易于理解和理解。
Si

I hope I have made this as easy to understand and put across. Si

推荐答案

尝试 switch

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

然后使用

var root = document.location.hostname + rootFolder;

这篇关于javascript网站root的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆