Javascript if body in body onload

时间:2013-05-16 13:51:38

标签: javascript onload

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

这就是我所拥有的

<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语句显然有问题。有人可以帮助我吗?

1 个答案:

答案 0 :(得分: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
    });
}
}
相关问题