获取网站跟路径的javascript代码(站点及虚拟目录)

代码如下:

<script>
function getRootPath(){
var strFullPath=window.document.location.href;
var strPath=window.document.location.pathname;
var pos=strFullPath.indexOf(strPath);
var prePath=strFullPath.substring(0,pos);
var postPath=strPath.substring(0,strPath.substr(1).indexOf('/')+1);
return(prePath+postPath);
}
alert (getRootPath());
</script>

(0)

相关推荐

  • javascript获取web应用根目录的方法

    复制代码 代码如下: <script> function getRootPath(){ var strFullPath=window.document.location.href; var strPath=window.document.location.pathname; var pos=strFullPath.indexOf(strPath); var prePath=strFullPath.substring(0,pos); var postPath=strPath.substring(

  • JavaScript获取当前运行脚本文件所在目录的方法

    本文实例讲述了JavaScript获取当前运行脚本文件所在目录的方法.分享给大家供大家参考,具体如下: DirectoryUtility = { // function getCurrentDirectory: returns currentDirectory path // with a trailing backslash. getCurrentDirectory : function ( ) { var scriptFullName = WScript.ScriptFullName; va

  • Javascript中使用A标签获取当前目录的绝对路径方法

    一谈到路径相关的问题,大家都会往window.location上想,确实这个对象提供了相当多的路径信息,其中常用的就包括: 1.location.href:当前页面的完整URL 2.location.pathname:当前URL中的路径名 3.location.hash:当前URL中的锚点 4.location.search:当前URL中的查询参数 然而,location没有一个属性能直接获得当前目录(不含文件名)的绝对路径.通过Google我发现了一些错误的方法,比如说把URL通过"/&quo

  • jsp编程获取当前目录下的文件和目录及windows盘符的方法

    本文实例讲述了jsp编程获取当前目录下的文件和目录及windows盘符的方法.分享给大家供大家参考,具体如下: (一)获取当前目录下的文件和目录 知识点 1 file对象的应用 2 listFiles()方法 3 isDirectory()方法,isFile()方法 判断是否为目录或是文件 4转换字符串方法toString (1)创建一个file对象dir, 然后用listFiles()方法返回当前目录下所有文件 String path=request.getRealPath("/")

  • jsp中获取当前目录的方法

    本文实例讲述了jsp中获取当前目录的实现方法,分享给大家供大家参考.具体实现方法如下: 1.利用System.getProperty()函数获取当前路径: 复制代码 代码如下: System.out.println(System.getProperty("user.dir"));//user.dir指定了当前的路径 2.使用File提供的函数获取当前路径: 复制代码 代码如下: File directory = new File("");//设定为当前文件夹 try

  • JavaScript学习笔记之获取当前目录的实现代码

    复制代码 代码如下: function GetCurrentDirectory() { var curHref = location.href; var curArray = locHref.split("/"); delete curArray[curArray.length - 1]; var curdir = curArray.join("/"); return curdir; }

  • 获取网站跟路径的javascript代码(站点及虚拟目录)

    复制代码 代码如下: <script> function getRootPath(){ var strFullPath=window.document.location.href; var strPath=window.document.location.pathname; var pos=strFullPath.indexOf(strPath); var prePath=strFullPath.substring(0,pos); var postPath=strPath.substring(

  • linux C++ 获取文件绝对路径的实例代码

    提供ftp服务时需要获取文件绝对路径,这里记录一下. #include <stdlib.h> #include <stdio.h> #include <limits.h> int main(){ const char *file_name = "filename"; char abs_path_buff[PATH_MAX]; //获取文件路径, 填充到abs_path_buff //realpath函数返回: null表示获取失败; 否则返回指向ab

  • C#实现获取IIS站点及虚拟目录信息的方法

    本文实例讲述了C#实现获取IIS站点及虚拟目录信息的方法.分享给大家供大家参考.具体如下: using System; using System.DirectoryServices; using System.Collections.Generic; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { DirectoryEntry rootEntr

  • asp.net获取网站绝对路径示例

    复制代码 代码如下: VirtualPathUtility.ToAbsolute( " ~/ " )HttpRuntime.AppDomainAppVirtualPathRequest.ApplicationPathPage.ResolveUrl( " ~ " ) 以上代码生成的结果如下:当以网站的方式访问时,结果如下: 复制代码 代码如下: VirtualPathUtility.ToAbsolute("~/") = /HttpRuntime.A

  • C++ 设置和获取当前工作路径的实现代码

    通常,你在服务程序中调用DLL,而DLL又会加载许多配置和文件,一般会出现DLL加载不到配置和文件,原因是你的服务程序被加载后,路径并不是你程序的所在目录,故DLL也不是,因此加载不了.解决办法,是在DLL的路径或服务程序中设计当前的工作路径. 主要函数为:SetCurrentDirectory: 设置当前工作路径实例如下: #include <iostream> #include <windows.h> #include <string> using namespac

  • 利用google提供的API(JavaScript接口)获取网站访问者IP地理位置的代码详解

    首先引入JavaScript API文件 <script type="text/javascript" src="http://j.maxmind.com/app/geoip.js"></script> 此API提供的接口共有6个,geoip_country_code(){国家代码},geoip_country_ name(){国家名称},geoip_city() {城市名称},geoip_region(){地区代码},geoip_latit

  • PHP获取网站域名和地址的代码

    复制代码 代码如下: <? function PMA_getenv($var_name) { if (isset($_SERVER[$var_name])) { return $_SERVER[$var_name]; } elseif (isset($_ENV[$var_name])) { return $_ENV[$var_name]; } elseif (getenv($var_name)) { return getenv($var_name); } elseif (function_exi

  • php获取网站根目录物理路径的几种方法(推荐)

    在PHP中获取网站根目录物理路径. 在php程序开发中经常需要获取当前网站的目录,我们可以通过常量定义获取站点根目录物理路径,方便在程序中使用. 下面介绍几种常用的获取网站根目录的方法. php获取网站根目录方法一: <?php define("WWWROOT",str_ireplace(str_replace("/","\\",$_SERVER['PHP_SELF']),'',__FILE__)."\\"); echo

  • JavaScript统计网站访问次数的实现代码

    本文实例讲述了JavaScript统计网站访问次数的实现代码.分享给大家供大家参考.具体如下: 运行效果截图如下: 完整代码: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>New Page 5</title> <meta name="GENERATOR&qu

  • Python 获取项目根路径的代码

    在 运行,调试,打包成exe 三个不同场景下获取跟路径,用于解决获取资源文件绝对路径问题. 工具类代码如下: import sys import os class pathutil(object): """路径处理工具类""" def __init__(self): # 判断调试模式 debug_vars = dict((a, b) for a, b in os.environ.items() if a.find('IPYTHONENABLE')

随机推荐