简体   繁体   English

根据区域调用JavaScript函数

[英]Call javascript function based on region

谁能告诉我如果在印度加载页面时如何调用一个javascript函数,而在其他国家加载页面时如何调用另一个javascript函数。

For that you need to get Visitor region. 为此,您需要获得Visitor地区。 This Code help You to find that. 此代码可帮助您找到该代码。 Reffer Reffer

<script type="text/javascript" src="http://www.google.com/jsapi?key=API_KEY_GOES_HERE"></script>

Then main script 然后是主脚本

    <script type="text/javascript">
    if(google.loader.ClientLocation)
    {
        visitor_lat = google.loader.ClientLocation.latitude;
        visitor_lon = google.loader.ClientLocation.longitude;
        visitor_city = google.loader.ClientLocation.address.city;
        visitor_region = google.loader.ClientLocation.address.region;
        visitor_country = google.loader.ClientLocation.address.country;
        visitor_countrycode = google.loader.ClientLocation.address.country_code;
        document.getElementById('yourinfo').innerHTML = '<p>Lat/Lon: ' + visitor_lat + ' / ' + visitor_lon + '</p><p>Location: ' + visitor_city + ', ' + visitor_region + ', ' + visitor_country + ' (' + visitor_countrycode + ')</p>';
    }
    else
    {
        document.getElementById('yourinfo').innerHTML = '<p>Whoops!</p>';
    }
</script>

After this find your client Region call the JavaScript to by region name. 之后,找到您的客户端Region,然后按地区名称调用JavaScript。

  1. store value of the country. 国家的商店价值。
  2. Call the JavaScript Functions Which you want call. 调用要调用的JavaScript函数。 Reffer Reffer

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM