一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

js获取url参数与路径方法

时间:2011-03-08 编辑:简简单单 来源:一聚教程网

js获取url参数与路径方法

如: http://localhost:8083/uimcardprjfunction getrootpath(){    //获取当

前网址,
如: http://localhost:8083/uimcardprj/share/meun.jsp   
var curwwwpath=window.document.location.href;    //获取主机地址之后的目

录,如: uimcardprj/share/meun.jsp   
var pathname=window.document.location.pathname;   
var pos=curwwwpath.indexof(pathname);    //获取主机地址,

如: http://localhost:8083   
var localhostpaht=curwwwpath.substring(0,pos);    //获取带"/"的项目名,

如:/uimcardprj  
 var projectname=pathname.substring(0,pathname.substr(1).indexof('/')

+1);   
return(localhostpaht+projectname);}

js参数表

网页特效
location property result
location.hash #test
location.host localhost:1351
location.hostname localhost
location.href http://localhost:1351/website1/dir/default.aspx/adsf?

id=12#test
location.pathname /website1/dir/default.aspx/adsf
location.port 1351
location.protocol http:
location.search ?id=12

热门栏目