【问题标题】:form to redirect to save cookie表单重定向以保存 cookie
【发布时间】:2012-09-29 10:19:41
【问题描述】:

大家好,我有这个代码;

<Script language="JavaScript">
function goto(form) { var index=form.select.selectedIndex
if (form.select.options[index].value != "0") {
location=form.select.options[index].value;}}
</SCRIPT>
<FORM NAME="form1">
<SELECT NAME="select" ONCHANGE="goto(this.form)" SIZE="1">
<OPTION VALUE="">-------Choose a Selection-------
<OPTION VALUE="/">Home
<OPTION VALUE="page.htm">Area 1
<OPTION VALUE="page.htm">Area2
<OPTION VALUE="page.htm">Area 3 
<OPTION VALUE="page.htm">Area 4
<OPTION VALUE="page.htm">Area 5</SELECT>
</FORM>

我想要做的是在用户单击其中一个时生成一个 cookie,然后当他们返回我的网站时,如果 cookie 存在,它将重定向到该页面。基本上这将是一个感兴趣的区域。虽然我想要它,如果他们想搜索其他地区,他们可以去其他地区。

我不知道我需要什么,有人可以帮我理解 cookie ui 以及我将如何将它实现到这段代码中吗?

如果您需要任何其他信息,请询问我愿意回答并提供更多信息

【问题讨论】:

    标签: javascript jquery forms cookies


    【解决方案1】:

    你可以调用这个函数

     <SELECT NAME="select" ONCHANGE="doThis(someParameters)" SIZE="1">
    

    然后包含这些javascript函数

    function setCookie(c_name,value,exdays)
    {
    var exdate=new Date();
    exdate.setDate(exdate.getDate() + exdays);
    var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
    document.cookie=c_name + "=" + c_value;
    }
    
    function doThis(someVal){
    if (someVal==1){
    setCookie("myCookie",someVal, someTime);
    window.location.href = "page1.htm"; // if u wish to redirect then itself
    }
    //similarly for others 
    if (someVal==2){
    
    }
    }
    

    【讨论】:

      猜你喜欢
      • 2018-10-21
      • 2013-04-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-29
      • 1970-01-01
      • 2016-05-18
      • 1970-01-01
      相关资源
      最近更新 更多