[js] Cookie. Wat wanneer cookies niet aanstaan?

Pagina: 1
Acties:
  • 47 views sinds 30-01-2008

  • Stalkert
  • Registratie: Januari 2001
  • Laatst online: 12-06 08:07
Ik heb de volgende code in mijn index.html staan. Opzich werkt dit prima. Maar nu was ik eens aan het kijken op computers met een andere versie van IE (met cookies aan of uit) en nu was het zo dat mijn pagina niet over doorlaadde.

Is er misschien een manier om meteen naar window.location.href = url; te gaan wanneer er een andere browser gebruikt wordt of wanneer cookies niet aanstaan zodat hij toch naar de goeie link gaat en niet blijft hangen ?

PHP:
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
<SCRIPT LANGUAGE="JavaScript">
var expDays = 30;
var exp = new Date(); 
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));


var myCookie = GetCookie('site');
if (myCookie != null) {
     switch (myCookie) {
        case 'english' :    url = 'en_index2.html';
                 SetCookie('site', 'english', exp);
                     break;
      case 'dutch' :        url = 'nl_index2.html'; 
                        SetCookie('site', 'dutch', exp);
            break;
            } 
}


if (myCookie == null) {
    SetCookie('toolshed2', 'dutch', exp);
    url = 'nl_index2.html'
}

window.location.href = url;

//  End -->

</script>

Verwijderd

setcookie() defines a cookie to be sent along with the rest of the header information. Cookies must be sent before any other headers are sent (this is a restriction of cookies, not PHP). This requires you to place calls to this function before any <html> or <head> tags. If headers exist prior to calling this function, setcookie() will fail and return FALSE. If setcookie() successfully runs, it will return TRUE This does not mean the user accepted the cookie or not.
je zou dus zeggen van niet, maar je kunt wel controleren met het setten van een cookie en vervolgens de waarde opvragen, lijkt me. Probleem is alleen dat daar een refresh voor nodig is.

HTH :)

  • RM-rf
  • Registratie: September 2000
  • Laatst online: 23:23

RM-rf

1 2 3 4 5 7 6 8 9

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<SCRIPT LANGUAGE="JavaScript">
var expDays = 30;
var exp = new Date(); 
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

var myCookie = GetCookie('site');
if (myCookie ==  'english') {
    url = 'en_index2.html'; 
    SetCookie('site', 'english', exp);   
} else {
    SetCookie('site', 'dutch', exp);
    url = 'nl_index2.html'
}
window.location.href = url;
</script>


is flink wat eenvoudiger, en werkt wel.
verder hoort (clientside) javascript in W&G, niet P&W

[ Voor 16% gewijzigd door RM-rf op 11-03-2003 00:00 ]

Intelligente mensen zoeken in tijden van crisis naar oplossingen, Idioten zoeken dan schuldigen


  • drm
  • Registratie: Februari 2001
  • Laatst online: 09-06-2025

drm

f0pc0dert

Zie RM-rf en de stickies bovenaan de topiclijst.

Music is the pleasure the human mind experiences from counting without being aware that it is counting
~ Gottfried Leibniz


Dit topic is gesloten.