2013-05-16 49 views
0

我只是需要一点帮助。我想要在我的索引上显示成功消息,但前提是有人来自发送电子邮件的php页面。Javascript if if in body onload

这是我

<script> 
function load() 
{ 
    if (document.referrer == 'http://www.blahblah.com/contact-form-handler.php') { 
     $.notify.success('We read you loud and clear; message received. Prepare for reply.', { 
      autoClose : 3000 
     }); 
    } 
} 
</script> 
</head> 

<body onload="load()"> 

这工作:

<script> 
function load() 
{ 
    $.notify.success('We read you loud and clear; message received. Prepare for reply.', {  autoClose : 3000 }); 
} 
</script> 
</head> 

<body onload="load()"> 

所以有很明显的if语句有点不妥。有人可以帮帮我吗?

+6

,如果你在'负荷做()''一个警报(document.referrer)'您能得到什么? – Lloyd

+1

也许如果条件永远不会在你的测试 –

+0

@Lloyd我得到index.html。嗯...我会尝试设置index.html作为推荐人。但是,如果有人只是刷新页面,它不会显示吗? – user2318958

回答

1

使用正则表达式与.match()

function load() 
{ 
if (document.referrer.match(/\/contact-form-handler.php/)) { 
    $.notify.success('We read you loud and clear; message received. Prepare for reply.', { 
     autoClose : 3000 
    }); 
} 
}