开发者

Set language settings in cookie from click of a link

Hi I have HTML like this

    <div class="header_countrys_middle">    
    <a href="http://www.test.com" title="United States"><img src="/images/flags/us.gif" alt="us" title="United States" /></a>
</div>

I set the language like this:

setcookie("lang", "en_开发者_运维问答US"); 

But how do I set the language based on users click?


You could be lazy and use:

 <a onClick="javascript:document.cookie='lang=en_US'"><img src=flags...>

Or use a server-side script:

 <a href="setlang.php?lang=en_US"> ..

With setlang.php being

 <?php
    setcookie("lang", urlencode($_GET["lang"]));


You could set an onclick event (and an ID to anchor element in order to select it easily)

<div class="header_countrys_middle">    
  <a href="http://www.test.com" id="lang" title="United States"><img src="/images/flags/us.gif" alt="us" title="United States" /></a>
</div>

document.getElementById('lang').onclick = function(){
  // this happens before the page changes
  setcookie('lang', 'en_US');
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜