ASP如何获取当前网站地址,网页地址代码及div+css菜单应用
分类:程序开发 Tags: asp 获取当前网址 评论:1 浏览:8065 最近更新时间:2008/5/30 23:15:03
1,如下简单的这句语句即能实现读取当前网站地址:
如果要替换掉网址中的某个字段,比如想把网址中的www去除就可以按照如下形式实现
例子:当前网页地址是http://www.yuzhiguo.com/blog/ ,程序就会输出http://www.yuzhiguo.com 的结果,简单吧!
2,如下简单的这句语句即能实现读取当前网页地址:
例子:当前网页地址是http://www.yuzhiguo.com/blog/ ,程序就会输出/blog/ 的结果,简单吧!
是不是觉得多了一个“/”斜杆,可以通过替换掉;如下代码:
3,获取带参数的网页地址
4,功能扩展:
这个代码我一开始主要是为我的一个饰品网站DIV+CSS导航而用起来的,打开http://www.yiwu-jewelry.cn即可看到如下导航:

开始的时候,当鼠标悬在“最新饰品“链接上,背景色会变成红色,点击之后背景色又回到了本身的黄色,都是我又想当点击之后保持红色,该怎么办呢?
当然也有几种实现方法,我现在考虑的是用程序判断的方式,最新饰品的网页地址是http://www.yiwu-jewelry.cn/jewelry_products_newjewelry.asp,当浏览器当前地址是/jewelry_products_newjewelry.asp时,你们程序就输出一段CSS样式定义代码,主要程序代码如下:
'(CSS代码部分省略)
<%
urlname=Request.ServerVariables("SCRIPT_NAME")
%>
<div id="menu">
<ul>
<li><a href="/index.asp" <%if urlname="/index.asp" then%>class="thisclass"<%end if%>>首页</a></li>
<li><a href="/jewelry_products_newjewelry.asp" <%if urlname="/jewelry_products_newjewelry.asp" then%>class="thisclass"<%end if%>>最新饰品</a></li>
<li><a href="/jewelry_products_goodjewelry.asp" <%if urlname="/jewelry_products_goodjewelry.asp" then%>class="thisclass"<%end if%>>推荐商品</a></li>
<li><a href="/jewelry_class.asp" <%if urlname="/jewelry_class.asp" then%>class="thisclass"<%end if%>>商品分类</a></li>
<li><a href="/jewelry_news.asp" <%if urlname="/jewelry_news.asp" then%>class="thisclass"<%end if%>>饰品资讯</a></li>
<li><a href="/about/huikuanfangshi.asp" <%if urlname="/about/huikuanfangshi.asp" then%>class="thisclass"<%end if%>>付款方式</a></li>
<li><a href="/about/yunshushuoming.asp" <%if urlname="/about/yunshushuoming.asp" then%>class="thisclass"<%end if%>>货物运输</a></li>
<li><a href="/guestbook.asp" <%if urlname="/guestbook.asp" then%>class="thisclass"<%end if%>>留言咨询</a></li>
<li><a href="/about/contact_us.asp" <%if urlname="/about/contact_us.asp" then%>class="thisclass"<%end if%>>联系我们</a></li>
</ul>
</div>
- <%=Request.ServerVariables("HTTP_HOST") %>
- <%=replace(Request.ServerVariables("HTTP_HOST"),"www.","") %>
2,如下简单的这句语句即能实现读取当前网页地址:
- <%=Request.ServerVariables("SCRIPT_NAME") %>
是不是觉得多了一个“/”斜杆,可以通过替换掉;如下代码:
- <%=replace(Request.ServerVariables("SCRIPT_NAME"),"/.","") %>
- '===========================================
- '获取当前Url参数的函数
- Function GetUrl()
- Dim ScriptAddress,Servername,qs
- ScriptAddress = CStr(Request.ServerVariables("SCRIPT_NAME"))
- Servername = CStr(Request.ServerVariables("Server_Name"))
- qs=Request.QueryString
- if qs<>"" then
- GetUrl ="http://"& Servername & ScriptAddress &"?"&qs
- else
- GetUrl ="http://"& Servername & ScriptAddress
- end if
- End Function
- '============================================
这个代码我一开始主要是为我的一个饰品网站DIV+CSS导航而用起来的,打开http://www.yiwu-jewelry.cn即可看到如下导航:

开始的时候,当鼠标悬在“最新饰品“链接上,背景色会变成红色,点击之后背景色又回到了本身的黄色,都是我又想当点击之后保持红色,该怎么办呢?
当然也有几种实现方法,我现在考虑的是用程序判断的方式,最新饰品的网页地址是http://www.yiwu-jewelry.cn/jewelry_products_newjewelry.asp,当浏览器当前地址是/jewelry_products_newjewelry.asp时,你们程序就输出一段CSS样式定义代码,主要程序代码如下:
'(CSS代码部分省略)
<%
urlname=Request.ServerVariables("SCRIPT_NAME")
%>
<div id="menu">
<ul>
<li><a href="/index.asp" <%if urlname="/index.asp" then%>class="thisclass"<%end if%>>首页</a></li>
<li><a href="/jewelry_products_newjewelry.asp" <%if urlname="/jewelry_products_newjewelry.asp" then%>class="thisclass"<%end if%>>最新饰品</a></li>
<li><a href="/jewelry_products_goodjewelry.asp" <%if urlname="/jewelry_products_goodjewelry.asp" then%>class="thisclass"<%end if%>>推荐商品</a></li>
<li><a href="/jewelry_class.asp" <%if urlname="/jewelry_class.asp" then%>class="thisclass"<%end if%>>商品分类</a></li>
<li><a href="/jewelry_news.asp" <%if urlname="/jewelry_news.asp" then%>class="thisclass"<%end if%>>饰品资讯</a></li>
<li><a href="/about/huikuanfangshi.asp" <%if urlname="/about/huikuanfangshi.asp" then%>class="thisclass"<%end if%>>付款方式</a></li>
<li><a href="/about/yunshushuoming.asp" <%if urlname="/about/yunshushuoming.asp" then%>class="thisclass"<%end if%>>货物运输</a></li>
<li><a href="/guestbook.asp" <%if urlname="/guestbook.asp" then%>class="thisclass"<%end if%>>留言咨询</a></li>
<li><a href="/about/contact_us.asp" <%if urlname="/about/contact_us.asp" then%>class="thisclass"<%end if%>>联系我们</a></li>
</ul>
</div>
本文地址:/347/
-
• ASP连接Access数据库绝对路径代码
• asp检测email地址是否有效函数
• ASP抽取数据的执行效率
• 在文章内容中随机插入网站版权文字,防止采集
• ASP过滤SQL非法字符并格式化html代码,不错的功能函数集
• centos系统挂载数据盘方法
• ASP Access数据库连接关闭与.ldb文件锁定解决方法
• 中国十大ASP CMS系统介绍
• MySQL报Field‘***’doesn’t have a default value错误的解决办法
• UEditor百度编辑器在html代码模式无法更新内容的解决办法