PageRenderTime 27ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/AndamanAlumni/Default.aspx

http://andamanalumini.codeplex.com
ASP.NET | 127 lines | 117 code | 10 blank | 0 comment | 31 complexity | 30cc67d702370f008fe7b0ff361e4569 MD5 | raw file
Possible License(s): GPL-2.0
  1. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="AndamanAlumni._Default" %>
  2. <%@ Register Assembly="Artem.GoogleMap" Namespace="Artem.Web.UI.Controls" TagPrefix="cc1" %>
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4. <html xmlns="http://www.w3.org/1999/xhtml">
  5. <head runat="server">
  6. <title></title>
  7. <script type="text/javascript">
  8. //IPInfoDB javascript JSON query example
  9. //Tested with FF 3.5, Opera 10, Chome 5 and IE 8
  10. //Geolocation data is stored as serialized JSON in a cookie
  11. //Bug reports : http://forum.ipinfodb.com/viewforum.php?f=7
  12. function geolocate(timezone, cityPrecision, objectVar) {
  13. var api = (cityPrecision) ? "ip-city" : "ip-country";
  14. var domain = 'api.ipinfodb.com';
  15. var url = "http://" + domain + "/" + api + "/?key=<your_api_key>&format=json" + "&callback=" + objectVar + ".setGeoCookie";
  16. var geodata;
  17. var callbackFunc;
  18. var JSON = JSON || {};
  19. // implement JSON.stringify serialization
  20. JSON.stringify = JSON.stringify || function (obj) {
  21. var t = typeof (obj);
  22. if (t != "object" || obj === null) {
  23. // simple data type
  24. if (t == "string") obj = '"' + obj + '"';
  25. return String(obj);
  26. } else {
  27. // recurse array or object
  28. var n, v, json = [], arr = (obj && obj.constructor == Array);
  29. for (n in obj) {
  30. v = obj[n]; t = typeof (v);
  31. if (t == "string") v = '"' + v + '"';
  32. else if (t == "object" && v !== null) v = JSON.stringify(v);
  33. json.push((arr ? "" : '"' + n + '":') + String(v));
  34. }
  35. return (arr ? "[" : "{") + String(json) + (arr ? "]" : "}");
  36. }
  37. };
  38. // implement JSON.parse de-serialization
  39. JSON.parse = JSON.parse || function (str) {
  40. if (str === "") str = '""';
  41. eval("var p=" + str + ";");
  42. return p;
  43. };
  44. //Check if cookie already exist. If not, query IPInfoDB
  45. this.checkcookie = function (callback) {
  46. geolocationCookie = getCookie('geolocation');
  47. callbackFunc = callback;
  48. if (!geolocationCookie) {
  49. getGeolocation();
  50. } else {
  51. geodata = JSON.parse(geolocationCookie);
  52. callbackFunc();
  53. }
  54. }
  55. //API callback function that sets the cookie with the serialized JSON answer
  56. this.setGeoCookie = function (answer) {
  57. if (answer['statusCode'] == 'OK') {
  58. JSONString = JSON.stringify(answer);
  59. setCookie('geolocation', JSONString, 365);
  60. geodata = answer;
  61. callbackFunc();
  62. }
  63. }
  64. //Return a geolocation field
  65. this.getField = function (field) {
  66. try {
  67. return geodata[field];
  68. } catch (err) { }
  69. }
  70. //Request to IPInfoDB
  71. function getGeolocation() {
  72. try {
  73. script = document.createElement('script');
  74. script.src = url;
  75. document.body.appendChild(script);
  76. } catch (err) { }
  77. }
  78. //Set the cookie
  79. function setCookie(c_name, value, expire) {
  80. var exdate = new Date();
  81. exdate.setDate(exdate.getDate() + expire);
  82. document.cookie = c_name + "=" + escape(value) + ((expire == null) ? "" : ";expires=" + exdate.toGMTString());
  83. }
  84. //Get the cookie content
  85. function getCookie(c_name) {
  86. if (document.cookie.length > 0) {
  87. c_start = document.cookie.indexOf(c_name + "=");
  88. if (c_start != -1) {
  89. c_start = c_start + c_name.length + 1;
  90. c_end = document.cookie.indexOf(";", c_start);
  91. if (c_end == -1) {
  92. c_end = document.cookie.length;
  93. }
  94. return unescape(document.cookie.substring(c_start, c_end));
  95. }
  96. }
  97. return '';
  98. }
  99. }
  100. </script>
  101. <script type="text/javascript">
  102. //function geolocate(timezone, cityPrecision, objectVar).
  103. //If you rename your object name, you must rename 'visitorGeolocation' in the function
  104. var visitorGeolocation = new geolocate(false, true, '172.16.29.239');
  105. debugger;
  106. //Check for cookie and run a callback function to execute after geolocation is read either from cookie or IPInfoDB API
  107. var callback = function () {
  108. alert('Visitor country code : ' + visitorGeolocation.getField('countryCode'))
  109. };
  110. visitorGeolocation.checkcookie(callback);
  111. </script>
  112. </head>
  113. <body>
  114. <form id="form1" runat="server">
  115. </form>
  116. </body>
  117. </html>