电子商务网站推荐超链接网址给好友功能代码
2010-08-26 15:26
453 查看
老是在一些网站上面看到推荐朋友,我做了一个简单例子,代码如下:
前台页面代码如下:
<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;
}
前台页面代码如下:
<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;
}
相关文章推荐
- 小功能JS代码——推荐给好友
- Social media sharing codes(各大网站网址分享功能代码)
- Social media sharing codes(各大网站网址分享功能代码)
- 用asp.net实现的把本文推荐给好友功能
- Python网站推荐:Pythontutor(可视化代码执行过程)
- 论坛源码推荐(9月19日):iOS 8新功能示例代码,为UILabel添加动画计数功能
- 对指定网站查找关键字且自动下页功能代码
- 仅需一行代码给网站添加一个功能
- 开源代码网站推荐
- 谷歌地点推荐服务Hotpot增“好友”功能
- 网站项目:让一般处理文件.ashx的代码有折叠功能(#region)
- 13个超棒的代码资源网站推荐
- 推荐找代码与文章的网站
- 典型电子商务网站功能模块
- 爬取网站的内容并建立索引,执行搜索功能 推荐
- 13个超棒的代码资源网站推荐
- 如何在richtextbox里实现网址的超链接,当点击该网址时就会打开网站
- 实现网站(网页)跳转且可隐藏跳转后网址的代码
- 新功能发布:推荐好友、邀请好友、邮件通知功能,欢迎试用。