页面导航: 首页网络编程ASP.NET基础应用 → 正文内容

获取当前url

发布:dxy 字体:[增加 减小] 类型:转载
如:http://localhost/newurl/WebForm1.aspx
1.方法document.URL(注意大小写)
结果是:http://localhost/newurl/WebForm1.aspx
2.HttpContext.Current.Request.Url.ToString(),
结果:http://localhost/newurl/WebForm1.aspx
3.HttpContext.Current.Request.Url.PathAndQuery;
结果:/newurl/WebForm1.aspx
备注:
如果当前URL为
http://localhost/search.aspx?user=tinyfool&tag=%BC%BC%CA%F5
通过HttpContext.Current.Request.Url.ToString()获取到的却是
http://localhost/search.aspx?user=tinyfool&tag=¼¼Êõ
这显然不对,怎么办?用HttpContext.Current.Request.Url.PathAndQuery好了,这个得到的正确的。:)

4.Javascript取url值 
刚写的一个小实例.实际中使用还是蛮多的.
点击运行可以看到效果:
[Ctrl+A 全选 提示:你可先修改部分代码,再按运行]
浏览次数:载入中... 打印本文关闭本文返回首页
·在百度中搜索关于“获取当前url”相关内容
·在谷歌中搜索关于“获取当前url”相关内容

文章评论

共有 位脚本之家网友发表了评论我来说两句

同 类 文 章
最 近 更 新
热 点 排 行