使用javascript显示指向电子邮件的推荐链接

时间:2013-01-17 01:14:52

标签: php javascript email referrals

我想显示我的电子邮件的推介链接。 这是我到目前为止所得到的。

<form method="POST" action="javascript:" name="form">
            <br /><label> <input type="text" name="text" id="text" placeholder="Name" value="" /> </label>
            <br /><label> <input type="text" name="email" id="email" placeholder="Email" value="" /> </label>
            <br /><label> <input type="text" name="phone" id="phone" placeholder="Phone" value="" /> </label>
            <br /><label> <input type="text" name="company" id="company" placeholder="Company" value="" /> </label> 
            <br /><label> <textarea name="textarea" id="textarea" placeholder="Message" rows="3" value="0" /></textarea> </label>
            <br /><label> <input type="text" name="referrer" id="WelcomePlaceHolder" placeholder="Referrer" value="" style="display: none;"/></textarea> </label>
        <br />
            <br /><label> <input class="homebotton" type="button" name="button" id="button" placeholder="button" value="Send" /> </label>
         </form>

表单已发送至电子邮件:

$message .= '<tr><td>Name : </td><td>' . $_REQUEST['text'] . '</td><tr>';
    $message .= '<tr><td>Email : </td><td>' . $_REQUEST['email'] . '</td></tr>';
    $message .= '<tr><td>Phone : </td><td>' . $_REQUEST['phone'] . '</td></tr>';
    $message .= '<tr><td>Company : </td><td>' . $_REQUEST['company'] . '</td></tr>';
    $message .= '<tr><td>Message : </td><td>' . $_REQUEST['textarea'] . '</td></tr>';
    $message .= '<tr><td>Referral Site : </td><td>' . $_REQUEST['referrer'] . '</td></tr>'; 

Javascript检索引荐来源链接。

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
//Add urls regular expressions and your message(any HTML Code) to the array
var msgs = [
//null url : to show a message for direct traffic (no referer, some one who remember your site url!)
{'url':null,                           'msg':'I am glad you remember my site URL, enjoy your stay'}
//My url! : show message for referrals from your own site or null so you do not annoy them
,{'url':/^http:\/\/(\w+\.)?moretechtips\.net/,    'msg':null}
//Other urls
,{'url':/^http:\/\/(\w+\.)?google\.com/,      'msg':'Welcome googler, Hope you will find what you looking for'}
,{'url':/^http:\/\/(\w+\.)?dzone\.com/,         'msg':'Welcome fellow dzone reader, if you like it please vote it up'}
,{'url':/^http:\/\/(\w+\.)?digg\.com/,         'msg':'Welcome digger, if you like it please digg it'}
,{'url':/^http:\/\/(\w+\.)?propeller\.com/,      'msg':'Welcome propeller user, hope you will like it here'}
//generic pattern: to show generic message for referrers that you did not specify one for
//You must keep it at the end of the list as it will match any non empty referrer
,{'url':/^http:\/\//,               'msg':'Hello their.. Hope you will find what you looking for'}
];
function DetectReferrer(){
   var div = $('#WelcomePlaceHolder');
   //if Div was not placed means , not to show message
   if (!div.length) return;
   var ref = document.referrer.toLowerCase();
   var msg = findMatch(ref);
   // if not null msg found
   if(msg) {
      //Add Close Button and Show up message
      div.html( '<a href="javascript:void(0)" class="CloseButton">X</a>' + msg).show('slow',function(){
         //Hide On click close Button
         $('.CloseButton',div).click(function(){ div.hide() })
      });
   }
}
function findMatch(ref) {
   for(var i=0; i<msgs.length; i++)
      if( ( ref=='' && msgs[i].url==null) || (ref>'' && ref.match(msgs[i].url) ) )
         return msgs[i].msg;
   return null;
}

// Call the Referrer Detector function on document ready
$(DetectReferrer);
</script>

此脚本有效。我试图显示发送到我的电子邮件的推荐链接,但它是空的。推荐链接为空。 我希望我有意义。

1 个答案:

答案 0 :(得分:0)

这将从电子邮件中的msgs表发送消息。

if(msg) {
   //Add Close Button and Show up message
   div.html( '<a href="javascript:void(0)" class="CloseButton">X</a>' + msg).show('slow',function(){
      //Hide On click close Button
      $('.CloseButton',div).click(function(){ div.hide() })
   });
   // Include message in form data
   div.val(msg);
}

如果你只想要referer URL,无论它是否在表中,只需执行:

div.val(ref);
if (msg)之前

要将此内容发送到PHP脚本,您需要将表单字段更改为:

<input type="hidden" name="referrer" id="WelcomePlaceHolder" placeholder="Referrer" value=""/>

display: none的表单字段不会发送到服务器,这是type="hidden"的用途。