日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

JavaScript獲取當(dāng)前文件全路徑、當(dāng)前目錄、當(dāng)前文件名

 madoutupiancom 2016-12-30
//獲取當(dāng)前文件全路徑
<script language="javascript"
alert(window.location.href);     //
alert(window.location);         //
alert(location.href);             //
alert(parent.location.href);         //
alert(top.location.href);             
alert(document.location.href); 
alert(document.URL);
</script>
//獲取當(dāng)前目錄方法
<script type="text/javascript">
//方法一
var str = location.href;
var arr = str.split("/");
delete arr[arr.length-1];
var dir = arr.join("/");
alert(dir);
//方法二
alert(location.href.substring(0,location.href.lastIndexOf('/')));
</script>
//獲取當(dāng)前文件名
<script   language=javascript>   
var  filename=location.href;
filename=filename.substr(filename.lastIndexOf('/')+1);   
alert(filename);   
</script>
如何用js得到當(dāng)前頁面的url信息方法(JS獲取當(dāng)前網(wǎng)址信息)    
設(shè)置或獲取對象指定的文件名或路徑。
alert(window.location.pathname)
  
設(shè)置或獲取整個 URL 為字符串。
  
alert(window.location.href);
設(shè)置或獲取與 URL 關(guān)聯(lián)的端口號碼。
alert(window.location.port)
  
設(shè)置或獲取 URL 的協(xié)議部分。
alert(window.location.protocol)
  
設(shè)置或獲取 href 屬性中在井號“#”后面的分段。
alert(window.location.hash)
  
設(shè)置或獲取 location 或 URL 的 hostname 和 port 號碼。
alert(window.location.host)
  
設(shè)置或獲取 href 屬性中跟在問號后面的部分。
alert(window.location.search)
  
  
獲取變量的值(截取等號后面的部分)
var url = window.location.search;
alert(url.length);
alert(url.lastIndexOf('='));
var loc = url.substring(url.lastIndexOf('=')+1, url.length);
JS獲取當(dāng)前網(wǎng)址,JS獲取當(dāng)前域名URL ,JS獲取網(wǎng)站完整路徑頁面地址
1.獲取當(dāng)前完整網(wǎng)址
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.獲取當(dāng)前域名信息
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.獲取當(dāng)前頁面
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 );

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多