余志国网站设计工作室是专业从事义乌网站建设、义乌外贸网站建设、义乌网站制作、义乌网站设计的专业义乌网站建设工作室,是义乌外贸网站建设专家!

ASP如何获取当前网站地址,网页地址代码及div+css菜单应用

分类:程序开发 Tags: asp 获取当前网址 评论:1 浏览:8441 最近更新时间:2008/5/30 23:15:03

1,如下简单的这句语句即能实现读取当前网站地址
 
  1. <%=Request.ServerVariables("HTTP_HOST")  %>
如果要替换掉网址中的某个字段,比如想把网址中的www去除就可以按照如下形式实现
 
  1. <%=replace(Request.ServerVariables("HTTP_HOST"),"www.","")  %>
例子:当前网页地址是http://www.yuzhiguo.com/blog/ ,程序就会输出http://www.yuzhiguo.com 的结果,简单吧!

2,如下简单的这句语句即能实现读取当前网页地址
 
  1. <%=Request.ServerVariables("SCRIPT_NAME")  %>
例子:当前网页地址是http://www.yuzhiguo.com/blog/ ,程序就会输出/blog/  的结果,简单吧!
是不是觉得多了一个“/”斜杆,可以通过替换掉;如下代码:
 
  1. <%=replace(Request.ServerVariables("SCRIPT_NAME"),"/.","")  %>
3,获取带参数的网页地址
 
  1. '===========================================
  2. '获取当前Url参数的函数
  3. Function GetUrl()
  4.   Dim ScriptAddress,Servername,qs
  5.   ScriptAddress = CStr(Request.ServerVariables("SCRIPT_NAME"))
  6.   Servername = CStr(Request.ServerVariables("Server_Name"))
  7.   qs=Request.QueryString
  8.   if qs<>"" then
  9.   GetUrl ="http://"& Servername & ScriptAddress &"?"&qs
  10.   else
  11.   GetUrl ="http://"& Servername & ScriptAddress
  12.   end if
  13. End Function
  14. '============================================
4,功能扩展
这个代码我一开始主要是为我的一个饰品网站DIV+CSS导航而用起来的,打开http://www.yiwu-jewelry.cn即可看到如下导航:
DIV+CSS导航代码
开始的时候,当鼠标悬在“最新饰品“链接上,背景色会变成红色,点击之后背景色又回到了本身的黄色,都是我又想当点击之后保持红色,该怎么办呢?
当然也有几种实现方法,我现在考虑的是用程序判断的方式,最新饰品的网页地址是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/
  • 相关文章
  • 推荐文章
  • 最新文章
发表评论





您的IP:18.97.14.88,来自:
小说
1. 小说 : 低调路过 2010/3/25 18:10:05

留言

 


免费咨询
建站咨询热线
15967985565
QQ: 358758308 Skype: yuzhiguo Facebook: yuzhiguo Email