ASP如何获取当前网站地址,网页地址代码及div+css菜单应用
分类:程序开发 Tags: asp 获取当前网址 评论:1 浏览:8441 最近更新时间: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获取图片宽度和高度的程序源代码
• js兼容IE、谷歌Chrome、火狐Firefox的上传图片预览代码
• ASP搜索关键词时结果用红色显示代码
• rs.open sql,conn,1,1和rs.open sql,conn,1,3的意思
• Dreamweaver 正则表达式字符查找替换方法
• UEditor百度编辑器1.4.3.3 ASP Utf-8版,上传图片文件服务器返回错误解决办法
• asp如何读取txt文本内容代码
• ASP数据库连接、显示、添加、删除、查询等简单操作教程
• asp使用CDO.Message发送邮件详细代码集合
• ASP实现点击链接直接下载文件的代码
-
• 去除windows 2003系统的登录界面
• 支付宝即时到账POST按钮代码
• 有用的CSS教程:18步改变你网站的css,使你从初学者成为高级用户(图)
• 国外网页版在线客服系统对比
• 2007年六一儿童节祝福短信/搞笑短信/经典手机短信大全
• asp获取内容中第一张图片和全部图片代码
• 关于摩托罗拉 MOTO E680G智能手机的一些问题解答
• win2003空间支持access2007、2010数据库.accdb的方法
• 如何实现鼠标移在图片上出现渐现的效果
• 微软Microsoft MSN账户登录Skype出错,无法识别您的详细登录信息,请检查您的Skype用户名和密码