JavaScript - How To Get Visitor's Country?
First off, I'm working with tumblr.com which allows Javascript, but not PHP embedded in the HTML pages. It strips them out.
I want to be able to get the country code (us, ca, uk, etc.) when a visitor visits my webpage so I can provide links for their locale. I'm having a very hard time finding correct information with examples to get this working. There was some .js libraries out there, but they don't work properly and say I'm in CA when I'm in US, like the jsapi from Google. Is there a way to execute a .php script which would output the country code of the visitor and be able to read/capture this result within the Javascript? Thanks in advance. Edward Similar TutorialsPlease help. I'm not sure why it's not populating. Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Blood Control</title> <meta name="keywords" content=""> <meta name="description" content=""> <META HTTP-EQUIV="Expires" CONTENT="0"> <META HTTP-EQUIV="Pragma" CONTENT="no-cache"> <!--- global javascript functions ---> <script language="JavaScript" type="text/javascript" src="https://www.bd.com/includes/global.js"></script> <!--- global style sheet ---> <LINK rel="stylesheet" type="text/css" href="https://www.bd.com/includes/styles.css" media="screen"> <!--- print style sheet ---> <LINK rel="stylesheet" type="text/css" href="https://www.bd.com/includes/print.css" media="print"> <!--- browser specific style sheets ---> <STYLE TYPE="text/css"> BODY { font-size: 75%; font-family : Verdana, Arial, Helvetica; color: #333333; } TD { font-size: 75%; font-family : Verdana, Arial, Helvetica; color: #333333; } </STYLE> <!----- HBX Include -----> <!-- HBX INCLUDE DATA HERE www.bd.com --> <!--WEBSIDESTORY CODE HBX1.0 (Universal)--> <!--COPYRIGHT 1997-2005 WEBSIDESTORY,INC. ALL RIGHTS RESERVED. U.S.PATENT No. 6,393,479B1. MORE INFO:http://websidestory.com/privacy--> <script language="javascript"> var _hbEC=0,_hbE=new Array;function _hbEvent(a,b){b=_hbE[_hbEC++]=new Object();b._N=a;b._C=0;return b;} var hbx=_hbEvent("pv");hbx.vpc="HBX0100u";hbx.gn="aa.bd.com"; //BEGIN EDITABLE SECTION //CONFIGURATION VARIABLES hbx.acct="DM531126I7FB72EN3";//ACCOUNT NUMBER(S) hbx.pn="PUT+PAGE+NAME+HERE";//PAGE NAME(S) hbx.mlc="CONTENT+CATEGORY";//MULTI-LEVEL CONTENT CATEGORY hbx.pndef="index.asp";//DEFAULT PAGE NAME hbx.ctdef="full";//DEFAULT CONTENT CATEGORY //OPTIONAL PAGE VARIABLES //ACTION SETTINGS hbx.fv="";//FORM VALIDATION MINIMUM ELEMENTS OR SUBMIT FUNCTION NAME hbx.lt="auto";//LINK TRACKING hbx.dlf="n";//DOWNLOAD FILTER hbx.dft="n";//DOWNLOAD FILE NAMING hbx.elf="n";//EXIT LINK FILTER hbx.lc="y";//FORCE LOWERCASE //SEGMENTS AND FUNNELS hbx.seg="";//VISITOR SEGMENTATION hbx.fnl="";//FUNNELS //CAMPAIGNS hbx.cmp="";//CAMPAIGN ID hbx.cmpn="";//CAMPAIGN ID IN QUERY hbx.dcmp="";//DYNAMIC CAMPAIGN ID hbx.dcmpn="";//DYNAMIC CAMPAIGN ID IN QUERY hbx.dcmpe="";//DYNAMIC CAMPAIGN EXPIRATION hbx.dcmpre="";//DYNAMIC CAMPAIGN RESPONSE EXPIRATION hbx.hra="";//RESPONSE ATTRIBUTE hbx.hqsr="";//RESPONSE ATTRIBUTE IN REFERRAL QUERY hbx.hqsp="";//RESPONSE ATTRIBUTE IN QUERY hbx.hlt="";//LEAD TRACKING hbx.hla="";//LEAD ATTRIBUTE hbx.gp="";//CAMPAIGN GOAL hbx.gpn="";//CAMPAIGN GOAL IN QUERY hbx.hcn="";//CONVERSION ATTRIBUTE hbx.hcv="";//CONVERSION VALUE hbx.cp="";//LEGACY CAMPAIGN hbx.cpd="";//CAMPAIGN DOMAIN //CUSTOM VARIABLES hbx.ci="";//CUSTOMER ID hbx.hc1="";//CUSTOM 1 hbx.hc2="";//CUSTOM 2 hbx.hc3="";//CUSTOM 3 hbx.hc4="";//CUSTOM 4 hbx.hrf="";//CUSTOM REFERRER hbx.pec="";//ERROR CODES //INSERT CUSTOM EVENTS //END EDITABLE SECTION //REQUIRED SECTION. CHANGE "YOURSERVER" TO VALID LOCATION ON YOUR WEB SERVER (HTTPS IF FROM SECURE SERVER) </script> <script language="javascript1.1" src="https://www.bd.com/includes/hbx.js"></script> <!--END WEBSIDESTORY CODE--> <!----- WT Include -----> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script language="javascript"> var rand_no = Math.floor(Math.random()*999999); // Declaring required variables var digits = "0123456789"; // non-digit characters which are allowed in phone numbers var phoneNumberDelimiters = "()#- ."; // characters which are allowed in international phone numbers // (a leading + is OK) var validWorldPhoneChars = phoneNumberDelimiters + "+"; // Minimum no of digits in an international phone no. var minDigitsInIPhoneNumber = 0; function form_action(form) { if (form.Share_Story.checked) { document.getElementById('share_story_enabled').style.display = 'block'; } else { document.getElementById('share_story_enabled').style.display = 'none'; } if (form.Share_Comment.checked) { document.getElementById('share_comment_enabled').style.display = 'block'; } else { document.getElementById('share_comment_enabled').style.display = 'none'; } if (form.Sign_Up.checked) { document.getElementById('sign_up_enabled').style.display = 'block'; } else { document.getElementById('sign_up_enabled').style.display = 'none'; } } </script> <script language="javascript"> function clearselect() { document.myform.State.options.length = 0; } function changeStates() { var indx=document.myform.Country.selectedIndex var Country=document.myform.Country.options[indx].value if (Country=="United States") { clearselect(); document.myform.State.options[0] = new Option('----- Select One -----',''); document.myform.State.options[1] = new Option('Alabama','AB'); document.myform.State.options[2] = new Option('Alaska','AK'); document.myform.State.options[3] = new Option('Arizona','AZ'); document.myform.State.options[4] = new Option('Arkansas','AR'); document.myform.State.options[5] = new Option('California','CA'); document.myform.State.options[6] = new Option('Colorado','CO'); document.myform.State.options[7] = new Option('Connecticut','CT'); document.myform.State.options[8] = new Option('Delaware','DE'); document.myform.State.options[9] = new Option('District of Columbia','DC'); document.myform.State.options[10] = new Option('Florida','FL'); document.myform.State.options[11] = new Option('Georgia','GA'); document.myform.State.options[12] = new Option('Hawaii','HI'); document.myform.State.options[13] = new Option('Idaho','ID'); document.myform.State.options[14] = new Option('Illinois','IL'); document.myform.State.options[15] = new Option('Indiana','IN'); document.myform.State.options[16] = new Option('Iowa','IA'); document.myform.State.options[17] = new Option('Kansas','KS'); document.myform.State.options[18] = new Option('Kentucky','KY'); document.myform.State.options[19] = new Option('Louisiana','LA'); document.myform.State.options[20] = new Option('Maine','ME'); document.myform.State.options[21] = new Option('Maryland','MD'); document.myform.State.options[22] = new Option('Massachusetts','MA'); document.myform.State.options[23] = new Option('Michigan','MI'); document.myform.State.options[24] = new Option('Minnesota','MN'); document.myform.State.options[25] = new Option('Mississippi','MS'); document.myform.State.options[26] = new Option('Missouri','MO'); document.myform.State.options[27] = new Option('Montana','MT'); document.myform.State.options[28] = new Option('Nebraska','NE'); document.myform.State.options[29] = new Option('Nevada','NV'); document.myform.State.options[30] = new Option('New Hampshire','NH'); document.myform.State.options[31] = new Option('New Jersey','NJ'); document.myform.State.options[32] = new Option('New Mexico','NM'); document.myform.State.options[33] = new Option('New York','NY'); document.myform.State.options[34] = new Option('North Carolina','NC'); document.myform.State.options[35] = new Option('North Dakota','ND'); document.myform.State.options[36] = new Option('Ohio','OH'); document.myform.State.options[37] = new Option('Oklahoma','OK'); document.myform.State.options[38] = new Option('Oregon','OR'); document.myform.State.options[39] = new Option('Pennsylvania','PA'); document.myform.State.options[40] = new Option('Puerto Rico','PR'); document.myform.State.options[41] = new Option('Rhode Island','RI'); document.myform.State.options[42] = new Option('South Carolina','SC'); document.myform.State.options[43] = new Option('South Dakota','SD'); document.myform.State.options[44] = new Option('Tennessee','TN'); document.myform.State.options[45] = new Option('Texas','TX'); document.myform.State.options[46] = new Option('Utah','UT'); document.myform.State.options[47] = new Option('Vermont','VT'); document.myform.State.options[48] = new Option('Virginia','VA'); document.myform.State.options[49] = new Option('Washington','WA'); document.myform.State.options[50] = new Option('West Virginia','WV'); document.myform.State.options[51] = new Option('Wisconsin','WI'); document.myform.State.options[52] = new Option('Wyoming','WY'); } else if (Country=="Canada") { clearselect(); document.myform.State.options[0] = new Option('---------------Select One-------------',''); document.myform.State.options[1] = new Option('Alberta','AB'); document.myform.State.options[2] = new Option('British Columbia','BC'); document.myform.State.options[3] = new Option('Manitoba','MB'); document.myform.State.options[4] = new Option('New Brunswick','NB'); document.myform.State.options[5] = new Option('New Foundland','NL'); document.myform.State.options[6] = new Option('NorthWest Territories','NT'); document.myform.State.options[7] = new Option('Nova Scotia','NS'); document.myform.State.options[8] = new Option('Ontario','ON'); document.myform.State.options[9] = new Option('Prince Edward Island','PE'); document.myform.State.options[10] = new Option('Quebec','QC'); document.myform.State.options[11] = new Option('Saskatchewan','SK'); document.myform.State.options[12] = new Option('Yukon','YT'); } else if (Country!="Canada" && Country!="United States") { clearselect(); document.myform.State.options[0] = new Option('Not Applicable','Not Applicable'); } } </script> </head> <body bgcolor="#ECF3FB" link="#2F61BD" vlink="#2F61BD" alink="#FF6600" marginheight="0" marginwidth="0" topmargin="0" leftmargin="0" onLoad="pageLoaded();"> <table border=0 cellpadding=0 cellspacing=0 width=768 align="center" bgcolor="#FFFFFF"> <tr> <td width=4 height=7 background="https://www.bd.com/images/shadow_left.gif" valign=top><img src="https://www.bd.com/images/shadow_top_left.gif" alt="[spacer image]" width="4" height="7" hspace="0" vspace="0" border="0"></td> <td width=760 rowspan=2 valign=top><!--- Global Header Include ---> <script type="text/javascript" src="https://www.bd.com/includes/anylink.js"> /*********************************************** * AnyLink CSS Menu script- © Dynamic Drive DHTML code library (www.dynamicdrive.com) * This notice MUST stay intact for legal use * Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code ***********************************************/ </script> Please help with the code details as to how this would be possible. Thanks. <form method="post" name="validate" action="internet_marketing_and_email_blasting_signup.php" enctype="multipart/form-data" onmouseover="change(event,'../images/submit1.png')" onmouseout="change(event,'../images/submit.png')" onkeyup="highlight(event)" onclick="highlight(event)"> Hi all new guy on the block here, I've got a website, and I want to add a welcoming message which hovers on a certain part of the page which only loads for the visitor for the first time they login, and won't again(presumably cookies used). And says something like "adjust your settings here.." I don't want it to be an external popup but something that loads on the page in a certain area, defined by me (PX-pixle reference) I think i nutted something out in a bit of PHP, this is what i've got so far PHP Code: <?php if (firstLogin()){ genSpecial(***load jquerie or css etc***); } else{ genRegular(); } ?> can anyone help me figure out how to make this all work and load a box from jquerie or something similar? thanks David Hello, I was wanting a message to be displayed if it is the visitors first time to the site. It will be a toolbar displayed at the top of the website, with links to FAQ's. Any method of display this is fine. Thanks Hello, I have recently started a website which tells visitor's IP address, location and others details. I want to add some more functions to it. I found no way to detect visitors Internet Service Provider (ISP) using PHP. I would like to know if there is any way to do so in Javascript. Click the below link to view the site: Show IP Please help me ASAP. Regards, Wasif K. Hello, Anyone know how to pop-up image for visitor that visiting for first time? the pop-up image should be appears 30seconds then it will open new window tab with adress page that i have attached to image then after 30seconds the pop-up automatically close. thx Hi everyone, Is it possible to determine at the startup of the page if the visitor is using a computer or a phone to access the site? I would like to make the intro process much better than a simple "click here for HTML version or click here for Flash version". I would like for it to simply redirect to the page I set it to go to depending on whether or not they're using a regular browser or a mobile browser. How would I go about this? Thank you all very much in advance. I have this floating banner code and I want to show it once per visitor. How could I have it to show once per visitor? <style> #floating_banner_bottom { text-align: left; width: 00%; bottom: 00px; margin-bottom: 0px; height: 50px; position: fixed; z-index: 50; left: 0px; </style> <div id="floating_banner_bottom"> <!-- Button to Close Banner --> <a style="display:scroll;position:fixed;bottom:50px;left:0px"> banner code <br /> <div class="close"> <a href="#" onclick="document.getElementById('floating_banner_bottom').style.display='none';return false;"> <i style="font-family: Georgia,"Times New Roman",serif;"><span style="background-color: #999999; color: white; font-size: small;"></span></i> <center> <img border="0" width="20" height="20" src="http://lh5.ggpht.com/_9vgJ1nwu_xA/S1jSp2ZhA7I/AAAAAAAAB8A/2AEBd4mR9qA/x.png" /> </center> </a> </div> <a/> </a></a></div> <!-- End Here --> Friends, I am looking for a PHP or Java Script to integrete in a PHP CMS, that enables to Redirect to Another URL when the script sense that the visitor is going away from the page. (Hit back button, hit refresh button and so on....) It should be unblockable by browsers. May anyone suggest me one or share the codes. I will use it for personal purpose and not for comercial purpose at all. Thanks My page has a form which has some sections that do not show unless needed, but if JS is turned off then these section will never show, so looking for a way to test if it is on or not and if not allow the page to display everything that would normally be hidden unless needed.
Im trying to figure out how to create a light box that doesn't close to reveal the content on the website, unless the user fully completes atleast 2-3 CPA(Cost Per Action) offers that will pop up in the lightbox? i know how to make a lightbox with a plugin from wordpress, but I just don't know how to make it so it'll close when it figures out the user has completed the surveys/offers. Kind of like this but maybe smaller to show there is content/download link behind it, http://sharecash.org/download.php?file=1595911 Does any know a code or a site I can get that from?
I'm looking for code which does the following: When a visitor visits my website and clicks anywhere on the page, (regardless of where the mouse clicks) it will automatically redirect him to another site. I think an event listener might be a solution, but I'm not sure. Thanks a lot for any help on this If possible, I would like there to be a 2 second time delay before it does the redirection. I have merged two scripts to make a popup that comes up even if blocked, and is for first time visitor only (cookie). The problem is that the way I'm doing it, it might show one or more times to the visitor. I don't want that because it will be irritating and this is a high-priority client. I'm posting the whole script because I think the problem is calling the popup before checking the cookie, but not sure how to rearrange things. Also, I did search and found some good dhtml stuff but don't want to rewrite. This was supposed to be done last night so if I can fine tune this for now, I'll have time to rewrite something better (or at least play around with another script). Also, the popup refuses to come up in IE - I have IE6, but I detest IE and their site doesn't even load in it so whatever. I tested in FFox3, Opera 10 and Safari and it seems to work but like I say because of the onclick - it will load at any click until the user goes to a different page. I added a refresh in there but it just made things worse - too much going on for the user at that point. Thanks for any suggestions. I hope I've used the right tags for this. I've highlighted the stuff at the bottom that I think is where I need the most help. Here is the code: // added for popup -kk var expDays = 100; // number of days the cookie should last //var page = "only-popup-once.html"; //var windowprops = "width=300,height=200,location=no,toolbar=no,menubar=no,scrollbars=no,resizable=yes"; var newwin = null; function openwin() { // window.location.reload(); var url = "/NEWSLETTER.html" try { if (newwin != null && typeof(newwin.location.href) != 'undefined') { newwin.location.href = url; } else { newwin = open(url, "Subscribe", "height=390,width=545,screenX=0,left=0,screenY=0,top=0,channelmode=0,dependent=0,directories=0,fulls creen=0,location=0,menubar=0,resizable=yes,scrollbars=0,status=0,toolbar=0"); } newwin.focus(); } catch (e) { newwin = open(url, "Subscribe", "height=390,width=520,screenX=0,left=0,screenY=0,top=0,channelmode=0,dependent=0,directories=0,fulls creen=0,location=0,menubar=0,resizable=yes,scrollbars=0,status=0,toolbar=0"); newwin.focus() } } function GetCookie (name) { var arg = name + "="; var alen = arg.length; var clen = document.cookie.length; var i = 0; while (i < clen) { var j = i + alen; if (document.cookie.substring(i, j) == arg) return getCookieVal (j); i = document.cookie.indexOf(" ", i) + 1; if (i == 0) break; } return null; } function SetCookie (name, value) { var argv = SetCookie.arguments; var argc = SetCookie.arguments.length; var expires = (argc > 2) ? argv[2] : null; var path = (argc > 3) ? argv[3] : null; var domain = (argc > 4) ? argv[4] : null; var secure = (argc > 5) ? argv[5] : false; document.cookie = name + "=" + escape (value) + ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + ((path == null) ? "" : ("; path=" + path)) + ((domain == null) ? "" : ("; domain=" + domain)) + ((secure == true) ? "; secure" : ""); } function DeleteCookie (name) { var exp = new Date(); exp.setTime (exp.getTime() - 1); var cval = GetCookie (name); document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString(); } var exp = new Date(); exp.setTime(exp.getTime() + (expDays*24*60*60*1000)); function amt(){ var count = GetCookie('count') if(count == null) { SetCookie('count','1') return 1 } else { var newcount = parseInt(count) + 1; DeleteCookie('count') SetCookie('count',newcount,exp) return count } } function getCookieVal(offset) { var endstr = document.cookie.indexOf (";", offset); if (endstr == -1) endstr = document.cookie.length; return unescape(document.cookie.substring(offset, endstr)); } function checkCount() { var count = GetCookie('count'); if (count == null) { count=1; SetCookie('count', count, exp); // window.open(page, "", windowprops); window.onclick = openwin; // window.location.reload(); } else { count++; SetCookie('count', count, exp); } } window.onload=checkCount; // end popup -kk Hi, I'm using javascript in addition to a web service (BTBuckets) to display different content to visitors based on actions they take on my site. The javascript is working fine, but I noticed that if I simulate BTBuckets being disabled using Firefox Adblock none of the content shows up. So in the off chance of the service going offline it'll leave some pretty funky holes in the my content. I tried <noscript> tags which works with javascript off, but the content is still blank when I disable BTBuckets. I'm wondering if there's a way to display the default content if the service is unavailable? Here's the code I'm using: In the head: Code: <script type="text/javascript"> //<![CDATA[[ $BTB={s:XXXXX}; $BTB.jsh="http://static.btbuckets.com/bt.js"; //]]> </script> <script type="text/javascript"> document.write(unescape("%3Cscript src='" + $BTB.jsh.replace(/(https?:)/i,document.location.protocol) + "' type='text/javascript'%3E%3C/script%3E")); </script> The code in the body used to replace an image depending on visitor behavior: Code: <script type="text/javascript"> var _t = ""; if ($BTB.clusters["ppc_visitors"]) { _t = "\"images/top-photo-tracking-number.jpg\" alt=\"Call Toll-Free: 1-800-XXX-XXXX\">"; } else { _t = "\"images/top-photo.jpg\" alt=\"Call Toll-Free: 1-800-XXX-XXXX\">"; } document.write('<img src= ' + _t ); </script> <noscript><img src="images/top-photo.jpg" alt="Call Toll-Free: 1-800-XXX-XXXX"></noscript> |