Get information about your visitor in a simple JavaScript Object.
{
"acceptedLanguages": [
"pt-BR",
"pt",
"en-US",
"en"
]
}
<script src="https://example.com/js"></script>
<script>
console.log(window.visitor.acceptedLanguages);
</script>
<script>
function visitorLoaded(visitor) {
console.log(visitor.acceptedLanguages);
}
</script>
<script src="https://example.com/jsonp?callback=visitorLoaded" async="async"></script>
Using jQuery it would look like the following, but you can use whichever framework or non-framework you please.
$.ajax('https://example.com/json').done(function(data) {
console.log(data.acceptedLanguages)
});
Originally created for greatstories.org, a static website that has no backend and but is viewable in multiple languages. The website needed to know the user's preferred languages to make accurate recommendations.
Abandoned when I realized I could use a series of simple tests to get the same information in JavaScript. I now use language.js.
The project contains a manifest.yml
and can be deployed to
CloudFounder/PivotalWS using cf push
.
The project contains a Procfile
and can be deployed to
Heroku out-of-the-box.