ASP如何获取当前网站地址,网页地址代码及div+css菜单应用
分类:程序开发 Tags: asp 获取当前网址 评论:1 浏览:8016 最近更新时间: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/
-
• rs.open sql,conn,1,1和rs.open sql,conn,1,3的意思
• opencart 3.0 PayPal Payments Standard支付没有传递收货地址解决办法
• 去除新版宝塔面板首页的强制手机登录窗口教程
• centos系统挂载数据盘方法
• Dreamweaver 正则表达式字符查找替换方法
• UEditor百度编辑器1.4.3.3 ASP Utf-8版,上传图片文件服务器返回错误解决办法
• asp如何读取txt文本内容代码
• 支付宝即时到账POST按钮代码
• asp获取内容中第一张图片和全部图片代码
• ASP提交Post数据到远程网站的方法
-
• 解决IE6下float浮动margin出现双倍距离问题
• ASP在线创建ACCESS表或添加字段代码
• 网站推广的29个方法
• 网页Title标题、Keywords关键词、description描述该怎么写才利于网站优化
• 通过互联网创业的门槛有多高?
• Dreamweaver提示“以下翻译器没有被加载”的解决方法
• 教你如何在Windows 7安装IIS7.5及配置IIS支持ASP教程(配图)
• 义乌人才网站网址收藏
• Fckeditor 2.6.3 ASP版增加检测上传文件是否为木马功能
• 最近我上火了!痛苦啊!
-
• Google Workspace gmail企业邮箱老板监控员工邮件操作方法
• zoho企业邮箱开启手机验证码双重认证教程
• 外贸网站如何使用Google Search Console谷歌管理员工具
• 腾讯企业邮箱开启安全登录后,如何登录foxmail收发信
• 获取小红书无水印图片的原理
• iis如何支持.webp图片格式访问
• FireFox火狐浏览器有用的设置方法记录
• 最新政策 Google免费版企业邮箱个人用途可以继续保留免费版
• MySQL报Field‘***’doesn’t have a default value错误的解决办法
• 抖音国际版TikTok注册过程记录