电子商务网站推荐超链接网址给好友功能代码

来源:互联网 发布:淘宝 关闭私人定制 编辑:程序博客网 时间:2024/06/05 06:15

老是在一些网站上面看到推荐朋友,我做了一个简单例子,代码如下:

前台页面代码如下:
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
    <link href="../style/common_5acss.css" rel="stylesheet" type="text/css" />
<link href="../style/recommend.css" rel="stylesheet" type="text/css" />
</head>
<script type="text/javascript">
    function copyLink(txt)
    {
        if (window.clipboardData)
        {
            //在复制文本之前先清除之前的内容
            window.clipboardData.clearData();
            //复制文本
            window.clipboardData.setData("Text", txt);
            alert("复制成功");
        }
        else if (navigator.userAgent.indexOf("Opera") != -1)
        {
            window.location = txt;
            alert("复制成功");
        }
        else if (window.netscape)
        {
            try
            {
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
            }
            catch (e)
            {
                alert("你使用的Firefox浏览器,复制功能被浏览器拒绝!/n请在浏览器地址栏输入'about:config'并回车/n然后将'signed.applets.codebase_principal_support'设置为'true',即可实现复制功能");
            }
            var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
            if (!clip)
                return;
            var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
            if (!trans)
                return;
            trans.addDataFlavor('text/unicode');
            var str = new Object();
            var len = new Object();
            var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
            var copytext = txt;
            str.data = copytext;
            trans.setTransferData("text/unicode", str, copytext.length * 2);
            var clipid = Components.interfaces.nsIClipboard;
            if (!clip)
                return false;
            clip.setData(trans, null, clipid.kGlobalClipboard);
            alert("复制成功");
        }
    }


    //-->
</script>

</script>
<body>
    <form id="form1" runat="server">
      <uc1:top  ID="top1" runat="server" />
  <div id="recommend" style="padding:20px 0;">
<li><img src="../images/broadcast.gif" width="43" height="36" style="padding-bottom:13px;" /></li>
<li><em>推荐好友来 优惠同时享!</em></li>

<br>
<span style="font-size:15px; border-bottom:1px dotted #ccc; padding:5px 50px;"> 好友注册就送500点奖励积分,您即可获50点推荐奖励积分!</span><br />
<br />
<ul><li><strong>用</strong><img src="../images/qq.gif" style="padding:0 5px;" /></li>
<li><img src="../images/msn.gif" style="padding-right:5px;" /></li>
<strong>等聊天工具发送邀请链接给朋友!</strong></ul><br />
<input name="textfield" type="text" id="textfield" size="50" runat="server" readonly />
  <asp:ImageButton ID="btnfuzhi" ImageUrl="../images/button_reco_copy.gif" runat="server" OnClientClick="copyLink(document.getElementById('textfield').value);" />
<br /><span style="color:#ccc;">
如果点击复制没有用,请全选后“ctrl+c”复制此链接
</span></div>
      <uc3:footer ID="footer1" runat="server" />
    </form>
</body>
</html>


后台代码:
protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                Poucan.BLL.Customer bll = new Poucan.BLL.Customer();
                Poucan.Model.Customer model = new Poucan.Model.Customer();
                string customercode = PageProduct.getCustomerName();   //得到登录用户名(此方法在下面)
                int CustomerID = bll.GetcustomerIDBycustomercode(customercode);   //根据用户名获取用户ID
                if (CustomerID>0)
                {
                    textfield.Value = "http://localhost:3333/User/recommend_reg.aspx?ID=" + CustomerID;
                }
                else
                {
                    textfield.Value = "http://www.5ashop.com";
                }
            }
        }


    /// <summary>
        /// 获取用户名称
        /// </summary>
        /// <returns>用户名称</returns>
        public static string getCustomerName()
        {
            //string path = "http://" + Request.Url.Authority + "/Homepage.aspx";
            string CustomerName = null;

            HttpCookie cookie_Receiverr = HttpContext.Current.Request.Cookies["Customer"];//获取用户信息
            if (cookie_Receiverr != null)
            {
                string strReceiverr = cookie_Receiverr.Value;

                if (strReceiverr != null)
                {
                    if (strReceiverr.Trim().Length > 0)
                    {
                        string[] str = strReceiverr.Split('=');
                        CustomerName = str[0].Trim();
                    }
                }
            }
            return CustomerName;

        }

原创粉丝点击