上次已经揭贴子了的问题,Javascript如何获取当前页面的正确路径!

gdmm 2004-04-30 02:29:34
pagename="http://expert.csdn.net/Expert/PostNew.asp?room=301"
能够正确解决,但是
pagename="http://expert.csdn.net:12345/mail.dll?View=Main"
又报告错了啊!

函数如下:

var pagename = window.location.href
function getHost(str)
{
var regUrl = /(\w+):\/\/([\w.]+)\/(\S*)/;
var result = str.match(regUrl);
if(result!=null) {
host=result[2].replace(/\b[\w]+\./,"");
return host;
}
}
//document.write (getHost(pagename))
...全文
118 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
postfix2 2004-04-30
  • 打赏
  • 举报
回复
<script>
x=location.href;
x=x.substr(0,x.indexOf("/",8))
x=x.substr(x.indexOf(".")+1)
alert(x)
</script>

xuwenfu 2004-04-30
  • 打赏
  • 举报
回复
没有错误
在试一下
wubaozhang 2004-04-30
  • 打赏
  • 举报
回复
window.location.href
BlueDestiny 2004-04-30
  • 打赏
  • 举报
回复
up
fenlin 2004-04-30
  • 打赏
  • 举报
回复
window.location
  • 打赏
  • 举报
回复
alert (window.location)
歪歪 2004-04-30
  • 打赏
  • 举报
回复
<script>
<!--
var x = document.URL;
var y = x.substr(x.indexOf(".")+1);
var z = y.substring(0,y.indexOf("/"));
var su = x + "\n" + y + "\n" + z + "\n";
alert(su);
-->
</script>
aspnetxp 2004-04-30
  • 打赏
  • 举报
回复
up...
wj253 2004-04-30
  • 打赏
  • 举报
回复
帮你顶
孟子E章 2004-04-30
  • 打赏
  • 举报
回复
<script>
x="http://expert.csdn.net:12345/mail.dll?View=Main"
x=x.substr(0,x.indexOf("/",8))
alert(x)
x=x.substr(x.indexOf(".")+1)
alert(x)
if(x.indexOf(":")>-1) x=x.substr(0,x.indexOf(":"))
alert(x)
</script>

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧