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