1

我有一个名为 form.html 的表单,当用户提交它时,它会跟随到 comformation.html。

但是,我不希望用户能够获取 comfirmation.html 页面 URL 并共享它(例如,推特它)

这可以通过在 form.html 中设置一个会话然后在 comfirmation.html 页面上进行某种检查来查看它是否存在来实现吗?

因此,如果其他人直接单击指向 comfirmation.html 的链接,那么他/她将被重定向到表单。

我认为这是可能的,因为我在谷歌搜索时看到了一些例子。但是我还没有看到会话检查重定向到另一个页面的任何示例(或者如果会话匹配,则什么也不做)。

谢谢,

劳伦斯

4

2 回答 2

1

如果在 Confirmation.html 中添加这样的代码怎么办?

var prevStage = "http://mysite.com/form.html";
if(prevStage != document.referrer) {
    window.location.href = prevStage;
}
于 2012-11-19T00:51:09.877 回答
0

我认为你可以做到这一点...

<html>
<head>
<script>


/* getUrlVars function from http://papermashup.com/read-url-get-variables-withjavascript/
*/
function getUrlVars() 
{
    var vars = {};
    var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
        vars[key] = value;
    });
    return vars;
}


/*
* getCookie and checkCookie function 
* credit http://www.w3schools.com/js/js_cookies.asp
*/

function getCookie(c_name)
{
    var i,x,y,ARRcookies=document.cookie.split(";");
    for (i=0;i<ARRcookies.length;i++)
    {
        x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
        y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
        x=x.replace(/^\s+|\s+$/g,"");
        if (x==c_name)
            {
                return unescape(y);
            }
    }
}


function checkCookie()
{
    var getConfirmationID = getUrlVars('confirmationid'); 
    var confirmation =getCookie(getConfirmationID);
    if (confirmation!=null && confirmation!="")
    {
        alert("Page expired, redirecting....");
        window.location = "/originalForm.html";

    }
    else
    {
        /*
        * show the confirmation
        */
        document.getElementById('confirmationdata').innerHTML = '<p>'+confirmation+'</p>';

    }

  }
}
</script>
</head>
<body onload="checkCookie()">
    <div id='confirmationdata'></div>
</body>
</html>
于 2012-11-19T01:04:43.073 回答