1

在 A 页

 test.Controls.Add(GetButton(thisReader["session_name"].ToString(), "Join Session"));

Response.Redirect("EnterSession.aspx?session=" + e.CommandArgument.ToString());

在 B 页

 _gaq.push(['pageTrackerTime._trackEvent', 'category', 'action', document.location.href, roundleaveSiteEnd]);

当用户单击页面 A 上的按钮时,他将被定向到页面 B 并且我使用 document.location.href 来跟踪当前 URL。现在我也想使用 JavaScript 从页面 A 跟踪 session_name。

我怎样才能做到这一点

原来的代码是这样的

SqlCommand thisCommand = thisConnection.CreateCommand();
                thisCommand.CommandText = "SELECT * FROM Tmyapp_Session;";
                SqlDataReader thisReader = thisCommand.ExecuteReader();

                while (thisReader.Read())
                {
                    test.Controls.Add(GetLabel(thisReader["session_id"].ToString(), thisReader["session_name"].ToString()));
                    string[] compare = secondResult.Split(';');
                    foreach (string word in compare)
                    {
                        if (word == thisReader["session_id"].ToString())

                        {
                            test.Controls.Add(GetButton(thisReader["session_id"].ToString(), "Join Session"));

我不得不将最后一个代码更改为

test.Controls.Add(GetButton(thisReader["session_name"].ToString(), "Join Session"));

session_idsession_name

因为我想通过 url 获得 session_name 的值

4

2 回答 2

0

看起来您只需要从查询字符串中获取 session_name 即可。在这里查看这篇文章,它有几个很好的解决方案。

我看到了两种完成你想要的方法,你可以添加另一个查询字符串

/url.aspx?session_name=[session_name]&session_id=[session_id]

或在会话变量中

session["session_id"] = session_id;
于 2012-04-07T12:03:47.140 回答
0
<HTML>
  <HEAD>
  <SCRIPT LANGUAGE="JavaScript">
      // include getCookie and setCookie functions here
    </SCRIPT>
  </HEAD>
  <BODY>
    <SCRIPT LANGUAGE="JavaScript">
      var username = getCookie("username");
      if (username != null) { // registered user
        document.writeln("Welcome back " + 
          username + ".");
        var visits = getCookie("visits");
        document.writeln(" You have been here " +
          visits + " time(s) before.");
        setCookie("visits",parseInt(visits)+1);
      }
      else {                  // new user
        var username = prompt("What is your name ?","");
        if (username != null) {
          setCookie("username",username);
          setCookie("visits",1);
          document.writeln("Thank you. Please reload this page.");
        }
      }
    </SCRIPT>
  </BODY>
</HTML>

希望这会奏效!

于 2012-04-07T06:42:25.840 回答