Welcome to TalkGraphics.com
Results 1 to 5 of 5
  1. #1

    Default show proper site depending on language stored in cookie

    Hello again,

    I have a site that exists in two languages : dutch and french (www.orthopedie-ronse.be/NL/index.htm)

    I have created two seperate sites with two flags in the top right corner to choose the language. These flags link to the proper site.

    I would like to remember the language the user chooses by registering a cookie and check on the existence of this cookie the next time the users enters the main site URL.

    I've looked on this forum on "cookies", "language" but did not find that much...

    I came up with this so far::

    - make an external file called cookieRedirect.js that contains the funtions:
    Code:
    var expDays = 30;
    var exp = new Date();
    exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
    
    function getCookieVal (offset) {
    var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1)
    endstr = document.cookie.length;
    return unescape(document.cookie.substring(offset, endstr));
    }
    function GetCookie (name) {
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
    return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break;
    }
    return null;
    }
    function SetCookie (name, value) {
    var argv = SetCookie.arguments;
    var argc = SetCookie.arguments.length;
    var expires = (argc > 2) ? argv[2] : null;
    var path = (argc > 3) ? argv[3] : null;
    var domain = (argc > 4) ? argv[4] : null;
    var secure = (argc > 5) ? argv[5] : false;
    document.cookie = name + "=" + escape (value) +
    ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
    ((path == null) ? "" : ("; path=" + path)) +
    ((domain == null) ? "" : ("; domain=" + domain)) +
    ((secure == true) ? "; secure" : "");
    }
    function DeleteCookie (name) {
    var exp = new Date();
    exp.setTime (exp.getTime() - 1);
    var cval = GetCookie (name);
    document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
    }
    
    var favorite = GetCookie('language');
    
    if (favorite != null) {
    switch (favorite) {
    case 'NL' : 	url = '/NL/index.htm';
    	     	break;
    case 'FR' : 	url = '/FR/index.htm';
    	     	break;
    }
    window.location.href = url;
    }
    I should then be able to put this javascript command into the onclick function of the dutch flag:

    SetCookie('language', "NL", exp);


    I've named the placeholder holding the javascript functions <head> to place the code in the head so it executes when loading the site....


    Can anyone help me a little further ? Where do i put the SetCookie command ?

    thank you,


    Olivier

  2. #2
    Join Date
    Jan 2004
    Posts
    1,830

    Default Re: show proper site depending on language stored in cookie

    Hi

    you would need to create a rectangle, select it and go to web properties followed by placeholder tab and replace with the following HTML code

    <a href="" name="NL" id="NL" onClick="SetCookie('language', this.name, exp);">NL</a>

    You could ensure the 2 images for the flags are uploaded to your server and then insert the following assuming the name of the image for the flag is called 5.png

    <a href="" name="NL" id="NL" onClick="SetCookie('language', this.name, exp);"><img src="http://www.orthopedie-ronse.be/NL/index_htm_files/5.png" border="0"></a>

    example of this at http://www.shaadibay.com/redirect/index1.htm
    thanks

  3. #3
    Join Date
    Jan 2004
    Posts
    1,830

    Default Re: show proper site depending on language stored in cookie

    The following should make this easier for you as the original post would require you to ensure the flag images already reside on your server. I didn't think about this until Steve pointed it out.

    1. import the bitmaps of the flags within the program.
    2. select the dutch flag, open the name gallery and apply the name filename="dutch"
    3. Clone the dutch flag so there is a copy over the top of the existing graphic.
    4. remove the name from the clone and replace with HTML

    <a href="" name="NL" id="NL" onClick="SetCookie('language', this.name, exp);"><img src="index_htm_files/dutch.png" border="0"></a>

    5. select the french flag open the name gallery and apply the name filename="french"
    6. Clone the french flag so there is a copy over the top of the existing graphic.
    7. remove the name from the clone and replace with HTML

    <a href="" name="FR" id="FR" onClick="SetCookie('language', this.name, exp);"><img src="index_htm_files/french.png" border="0"></a>

    example at http://www.shaadibay.com/redirect/index2.htm
    Attached Files Attached Files

  4. #4

    Default Re: show proper site depending on language stored in cookie

    One other Step Bhav, the flag image should be set to export as PNG type from the Image tab of the Web Properties box otherwise these small bitmaps will be exported as JPG and this would mean the placeholder code would be looking for the wrong image extension.

  5. #5

    Default Re: show proper site depending on language stored in cookie

    thank you very much bb2 for your example and effort !

    I've aplied your instruction to my NL/index.htm page... this works !

    now i've aplied the same to the FR/index.htm page and I get some sort of loop ?

    I opened NL/index.htm and clicked on the french icon -> this sets the cookie taal (language) to F, reloads the page and gets redirected to FR/index.htm
    but while the FR page loads it checks the cookie which is set to F and redirects again to FR/index.htm and again, and again I think....

    should i modify the script on the FR/index.htm page ?

 

 

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •