php - Choose language popup on page load - Stack Overflow

I am building a multilingual site and I want to insert a function, on initial page load, that finds the

I am building a multilingual site and I want to insert a function, on initial page load, that finds the default language setting of the browser and then prompts the user to choose which language they would like. (Eng/Esp)

Of course the language in the prompt would be in the same language of the browser. I already have navigation between these languages on all pages page but I want to intercept the user upon entrance and avoid using a splash page.

Can anybody advise me on how this is done?

I am building a multilingual site and I want to insert a function, on initial page load, that finds the default language setting of the browser and then prompts the user to choose which language they would like. (Eng/Esp)

Of course the language in the prompt would be in the same language of the browser. I already have navigation between these languages on all pages page but I want to intercept the user upon entrance and avoid using a splash page.

Can anybody advise me on how this is done?

Share Improve this question asked Feb 28, 2013 at 13:49 Adam BrownAdam Brown 2,8704 gold badges31 silver badges39 bronze badges 6
  • Insert call to popup function in $(document).ready(function(){ }); – Deadlock Commented Feb 28, 2013 at 13:56
  • @Deadlock Hello, thank you, but my knowledge of JS is still very limited. I only understand basic console.log, return, print, etc. Could you explain a little more or perhaps you know a link? – Adam Brown Commented Feb 28, 2013 at 14:00
  • @Deadlock I don't see a jQuery tag. – Ron van der Heijden Commented Feb 28, 2013 at 14:08
  • $ is a shortcut for jquery @Bondye – Deadlock Commented Mar 1, 2013 at 4:46
  • @Deadlock Lol I know that. But your ment you say he has to use jQuery for this, but the OP don't have the jquery tag bounded on the question... – Ron van der Heijden Commented Mar 1, 2013 at 7:35
 |  Show 1 more ment

3 Answers 3

Reset to default 3

First you need a custom event listener

function addEvent(to, type, fn) {
    // Firefox, Safari, Chrome, Opera
    if(document.addEventListener) {
        to.addEventListener(type, fn, false)
    }
    // Microsoft ActiveX Scripts
    else if(document.attachEvent) {  
        to.attachEvent('on'+type, fn)
    }
    // Last hope
    else {  
        to['on'+type] = fn
    }
}

Add event listener on the window when its loaded and run the function onDomLoaded()

addEvent(window, 'load', onDomLoaded)

Create the function onDomLoaded

function onDomLoaded() {
    alert('Im finished loading the entire window, your language is: ' + navigator.language)

}

Here the example on jsFiddle

Like Deadlock has said you can use a JavaScript Modal pop-up. Someone has given an example of this Here.

You can create this pop-up containing buttons to select the language.

Answer on how to get the browser language using JavaScript. And as you specified PHP in your question tags, answer to do so with PHP.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745269213a4619641.html

相关推荐

  • php - Choose language popup on page load - Stack Overflow

    I am building a multilingual site and I want to insert a function, on initial page load, that finds the

    3小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信