2017-03-08 71 views
1

我想仅在来自印度的用户在我的博客博客中显示一些链接。但只有与js,没有PHP或任何其他语言。仅在特定国家/地区显示链接

+0

可能重复的[如何使用JavaScript获取浏览器语言](http://stackoverflow.com/questions/8199760/how-to-get-the-browser-language-using-javascript) –

+0

可能是重复的[如何使用JavaScript地理位置获取访问者的位置(即国家)](http://stackoverflow.com/questions/3489460/how-to-get-visitors-location-ie-country-using-javascript-geolocation)。 – Chad

回答

-1

您可以阅读导航器进行本地化并更改html元素的属性。

Using language | NavigatorLanguage.language

使用位置| Navigator.geolocation(不能发布2个链接)
“developer.mozilla.org/en-US/docs/Web/API/Navigator/geolocation”

const changeLink = document.querySelector(".theLinkThatChanges"); 

if (window.navigator.language == 'EN') { 
    changeLink.setAttribute("src", "https://www.englishlink.here"); 
} 

注:我加了我自己的答案后点击通过那些没有明确答案的“重复”中的4个。

相关问题