Grails, JavaScript gets the current deployment project path

Source: Internet
Author: User

JavaScript gets the current deployment project path:

The main use of the Location object, which contains information about the current URL, is a part of the Window object that can be accessed through the Window.location property.

Method One (window.document.location.href/window.document.location.pathname)------------ transferred from the network

functionGetrootpath_web () {//get the current URL, such as: http://localhost:8083/uimcardprj/share/meun.jsp            varCurwwwpath =Window.document.location.href; //gets the directory after the host address, such as: uimcardprj/share/meun.jsp            varPathName =Window.document.location.pathname; varpos =Curwwwpath.indexof (pathName); //get host address, such as: http://localhost:8083            varLocalhostpaht = curwwwpath.substring (0, POS); //get the project name with "/", such as:/uimcardprj            varProjectName = pathname.substring (0, Pathname.substr (1). IndexOf ('/') + 1); return(Localhostpaht +projectName); }

Method Two (Window.location.pathname/window.location.protocol/window.location.host)

function getrootpath_dc () {            var pathName = window.location.pathname.substring (1);             var webName = PathName = = "? ": pathname.substring (0, Pathname.indexof ('/'));             if (WebName = = "")                {return Window.location.protocol + '//' + window.location.host            ;}             Else {                return Window.location.protocol + '//' + Window.location.host + '/' + webName;            }        }

Note:

1, the document is implied by an object, window is the object of a Windows, a window can have more than one document object.
So there is only one window.location.href under a window, but there may be multiple document.url, document.location.href------------ transferred from the network

2, Window.location.href and document.location.href can be assigned value, and then jump to other pages, Document.url can only read cannot write------------ transferred from the network

3. Location Object Details Reference W3school http://www.w3school.com.cn/jsref/dom_obj_location.asp

Grails gets the current deployment project path:

  

System.getproperty ("User.dir");//    /users/hongmei1/ideawork/wechatshow   

Grails, JavaScript gets the current deployment 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.