JS如何在当前目录创建txt文件

JavaScript09

JS如何在当前目录创建txt文件,第1张

<script type="text/javascript">

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 )

</script>

<script type="text/javascript">

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 )

</script>

<script type="text/javascript">

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 )

</script>

不清楚你说的根目录是哪个根目录,JavaScript运行于浏览器沙盒模式中,无法和系统进行交互,所以你就别指望能直接获取物理计算机的磁盘目录了,如果是获取url的某曾目录,可以使用正则表达式匹配,或者检索字符串等等。