JS获取当前网址,JS获取当前域名URL ,JS获取网站完整路径页面地址

WEB前端 无名氏 2211℃ 百度已收录 扫描二维码

1.获取当前完整网址

thisURL = document.URL;
thisHREF = document.location.href;
thisSLoc = self.location.href;
thisDLoc = document.location;
strwrite = " thisURL:  [" + thisURL + "]<br />"
strwrite += " thisHREF:  [" + thisHREF + "]<br />"
strwrite += " thisSLoc:  [" + thisSLoc + "]<br />"
strwrite += " thisDLoc:  [" + thisDLoc + "]<br />"
document.write( strwrite );

2.获取当前域名信息

thisTLoc = top.location.href;
thisPLoc = parent.document.location;
thisTHost = top.location.hostname;
thisHost = location.hostname;
strwrite = "  thisTLoc:  [" + thisTLoc + "]<br />"
strwrite += " thisPLoc:  [" + thisPLoc + "]<br />"
strwrite += " thisTHost:  [" + thisTHost + "]<br />"
strwrite += " thisHost:  [" + thisHost + "]<br />"
document.write( strwrite );

3.获取当前页面

tmpHPage = thisHREF.split( "/" );
thisHPage = tmpHPage[ tmpHPage.length-1 ];
tmpUPage = thisURL.split( "/" );
thisUPage = tmpUPage[ tmpUPage.length-1 ];
strwrite = " thisHPage:  [" + thisHPage + "]<br />"
strwrite += " thisUPage:  [" + thisUPage + "]<br />"
document.write( strwrite );

本文固定链接:成事博客JS获取当前网址,JS获取当前域名URL ,JS获取网站完整路径页面地址
喜欢 (0)分享 (0)