html页面静态页面实现统计访问人数实例代码

本文介绍两种统计网页访问量的方法:一是通过JavaScript动态更新页面元素显示访问次数;二是利用图片请求展示访问数量,同时提供了相应的C#后台实现代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

详细请点击:http://www.verydemo.com/demo_c101_i57839.html



  1. 静态页面 staticHtml.html
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>">
  3. <html xmlns="<http://www.w3.org/1999/xhtml>" >
  4. <head>
  5. <title>统计动态页面访问量的几种方法</title>
  6. </head>
  7. <body>
  8. 这是在层中显示
  9. <div id="pv"></div>
  10. <script src="act.aspx"></script>
  11. </body>
  12. </html>
  13. 累加页面 act.aspx
  14. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="act.aspx.cs" Inherits="AddNumber" %>
  15. act.aspx.cs
  16. 代码
  17. public partial class AddNumber : System.Web.UI.Page
  18. {
  19.     private static int count = 1;
  20.     protected void Page_Load(object sender, EventArgs e)
  21.     {
  22.         count ;
  23.         Response.Write("var pv=document.getElementById(pv); pv.innerText=" count ";");
  24.     }
  25. }
  26. 静态页面 staticHtml.html
  27. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>">
  28. <html xmlns="<http://www.w3.org/1999/xhtml>" >
  29. <head>
  30. <title>统计动态页面访问量的几种方法</title>
  31. </head>
  32. <body>
  33. 这是利用图片进行显示
  34. <img src="Imageact.aspx" alt="这是动态统计的数量" />
  35. </body>
  36. </html>
  37. 累加页面 Imageact.aspx
  38. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Imageact.aspx.cs" Inherits="ImageAddNumber" %>
  39. Imageact.aspx.cs 代码
  40. public partial class ImageAddNumber : System.Web.UI.Page
  41. {
  42.     private static int count = 1;
  43.     protected void Page_Load(object sender, EventArgs e)
  44.     {
  45.         count ;
  46.         string pv = count.ToString();
  47.         System.Drawing.Bitmap image = new System.Drawing.Bitmap((int)Math.Ceiling((pv.Length * 12.5)), 22);
  48.         Graphics g = Graphics.FromImage(image);
  49.         //图片背景色
  50.         g.Clear(Color.White);
  51.         Font font = new System.Drawing.Font("Arial", 12, (System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic));
  52.         System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height), Color.White, Color.Red, (float)1.2f, true);
  53.         g.DrawString(pv,font, brush, 0, 0);
  54.         g.DrawRectangle(new Pen(Color.Gold), 0, 0, image.Width - 1, image.Height - 1);
  55.         System.IO.MemoryStream ms = new System.IO.MemoryStream();
  56.         image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
  57.         Response.ClearContent();
  58.         Response.ContentType = "image/Gif";
  59.         Response.BinaryWrite(ms.ToArray());
  60.     }
  61. }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值