JavaScript access path design Source _javascript Tips

Source: Internet
Author: User

1. Design Source

Copy Code code as follows:

<%@ page language= "java" import= "java.util.*" pageencoding= "UTF-8"%>

<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >

<title>javascript Get Path </title>

<meta http-equiv= "Pragma" content= "No-cache" >
<meta http-equiv= "Cache-control" content= "No-cache" >
<meta http-equiv= "Expires" content= "0" >
<meta http-equiv= "keywords" content= "keyword1,keyword2,keyword3" >
<meta http-equiv= "description" content= "This are my page" >
<script type= "Text/javascript" >
function Findpath ()
{
Get current URL
var curnetaddr = Window.document.location.href;
Alert ("Get current URL: + curnetaddr");

Get the directory after the host address
var hostpath = Window.document.location.pathname;
Alert ("Get the directory after the host address:" + Hostpath);

Returns the location of the first occurrence of a specified string value in a string
var count = Curnetaddr.indexof (Hostpath);
Alert ("Returns the location of the first occurrence of a specified string value in the string:" + count);

Get host Address
var hostaddr = curnetaddr.substring (0,count);
Alert ("Get host Address: + HOSTADDR");

Get the name of the project with "/"
var projectname = hostpath.substring (0,hostpath.substr (1). IndexOf ('/') +1);
Alert ("Get the project name with/": + ProjectName);

Get Project Path
var path = hostaddr + projectname;
Alert ("Get Project path:" + path);
}
</script>


<body>
<div id= "Body_div" >
<input type= "button" id= "btn" value= "Get Path" onclick= "Findpath ()"/>
</div>
</body>

2. Design result

(1) When initializing

(2) Get the current URL

(3) Get the directory after the host address

(4) Returns the location of the first occurrence of a specified string value in a string

(5) Get the host address

(6) Get the project name with "/"

(7) Get the project path

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.