Essaye la methode cookie, mais attention c'est du brute force,
<input type=text class="memorize" size=7 name="toto" value="" style="border-color:rgb(255,102,255); border-style:dotted;">
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
<script>
var memoryduration="100 days"
function setformobjects(){
var theforms=document.forms
memorizearray=new Array()
for (i=0; i< theforms.length; i++){
for (j=0; j< theforms[i].elements.length; j++){
if (theforms[i].elements[j].className.indexOf("memorize")!=-1 && theforms[i].elements[j].type=="text")
memorizearray[memorizearray.length]=theforms[i].elements[j]
}
}
var retrievedvalues=get_cookie("mvalue"+window.location.pathname)
if (retrievedvalues!=""){
retrievedvalues=retrievedvalues.split("|")
if (retrievedvalues[retrievedvalues.length-1]!=parseInt(memoryduration)) //reset cookie if var memoryduration has changed
resetcookie("mvalue"+window.location.pathname)
else{
for (i=0; i<memorizearray.length; i++){
if (retrievedvalues[i]!="empty_value")
memorizearray[i].value=retrievedvalues[i]
}
}
}
}
function get_cookie(Name) {
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) { // if cookie exists
offset += search.length
end = document.cookie.indexOf(";", offset);
if (end == -1)
end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}
function resetcookie(id){
var expireDate = new Date()
expireDate.setDate(expireDate.getDate()-10)
document.cookie = id+"=;path=/;expires=" + expireDate.toGMTString()
}
function saveformvalues(){
var formvalues=new Array(), temp
for (i=0; i<memorizearray.length; i++){
temp=memorizearray[i].value!=""? memorizearray[i].value : "empty_value"
formvalues[formvalues.length]=escape(temp)
}
formvalues[formvalues.length]=parseInt(memoryduration)
formvalues=formvalues.join("|")
var expireDate = new Date()
expireDate.setDate(expireDate.getDate()+parseInt(memoryduration))
document.cookie = "mvalue"+window.location.pathname+"="+formvalues+"; path=/;expires=" + expireDate.toGMTString()
}
if (window.addEventListener)
window.addEventListener("load", setformobjects, false)
else if (window.attachEvent)
window.attachEvent("onload", setformobjects)
else if (document.getElementById)
window.onload=setformobjects
if (document.getElementById)
window.onunload=saveformvalues
</script> |
Partager