JavaScript - How To Determine If A Visitor Is Using A Phone Or Computer
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. Similar TutorialsHey guys, I need to create a constructor for a computer object. This object must have three properties: speed, and mem_live mem_dead. Then I need to create a new object using this constructor and then have its properties displayed on the screen. Look at what I'm up to so far: Quote: function Computer(speed, mem_live, mem_dead) { this.speed = speed; this.mem_live = mem_live; this.mem_dead = mem_dead; } var computer1 = new Computer("4.0ghz", true, false); document.write(computer1.speed + " " + computer1.mem_live + " " + computer1.mem_dead); What am I doing wrong? It always just shows : 4.0ghz, true, false 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 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 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, 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 Hi, I have a click event that changes an element from a span that acts like a text link, to a textbox that the user types in: Code: Event.add(area_el_rename, 'click', function(e) { if(!currently_renaming) { area_el.innerHTML = '<textarea name=\"renaming_area\" id=\"renaming_area\" style=\"width:100px;height:10px;background-color:#DCDCDC; resize:none;font-size:8px;\"></textarea><br>'; currently_renaming=true; } }); I am wondering if there is any way to determine if the user has clicked outside the textbox, and if so, perform an action (in my case revert back to the <span>. The solution probably doesn't need to be tied to anything. It probably just has to be something like: if(click_outside_id("renaming_area")) { //do my desired action } Referring to following link, I would like to determine the link for "In-Depth.xls", based on following coding, I find related information for Excel.png, does anyone have any suggestions on how to determine the URL for Excel file? Thanks in advance for any suggestions http://fx.aastocks.com/en/forex/mark...0&indicator=47 <img src="../../images/common/Excel.png" id="cp_imgExcel" class="btn" onclick="window.location.href='dbindepth.aspx?country=66970&startdate=2010/12/24&enddate=2011/12/24&indicator=47&excel=1'"/> THIS IS NOT HOMEWORK Hi all, See this image: The image represents an "entire" web page and the bright part the area currently scrolled into by the web browser. I can get the client's screen SIZE, but I don't know how to figure how many pixels down into a page the browser happens to be. To clarify, the distance shown as a question mark would be "zero" if the browser were scrolled all the way to the top of the page and some positive number as the browser scrolls down. Is there any way for me to get this number (in Javascript). What I need it for is to position a pop-up window centered left-to-right and 1/3-2/3 top to bottom on the screen REGARDLESS of where in the page the browser is scrolled. Thanks..... -- Roger HI all. How do I determine whether a variable exists in a form. I have a form called "theForm". I want to determine whether the variable "THIRD_PARTY" exists in the form and if it has been set. Tracy Hello! I do my calendar (vertical) =) and I've done to date were down But how to do that day of the week displayed on the side of the date of Here is code: Code: <html><head><title>Calendar</title> <meta http-equiv="content-type" content="text/html; charset=windows-1251" /> </head> <body><center> <SCRIPT LANGUAGE="JavaScript"> <!-- Begin monthnames = new Array("January","Febrary","March","April","May","June","July","August","September","October","November","December"); var linkcount=0; function addlink(month, day, href) { var entry = new Array(3); entry[0] = month; entry[1] = day; entry[2] = href; this[linkcount++] = entry; } Array.prototype.addlink = addlink; linkdays = new Array(); monthdays = new Array(12); monthdays[0]=31; monthdays[1]=28; monthdays[2]=31; monthdays[3]=30; monthdays[4]=31; monthdays[5]=30; monthdays[6]=31; monthdays[7]=31; monthdays[8]=30; monthdays[9]=31; monthdays[10]=30; monthdays[11]=31; todayDate=new Date(); thisday=todayDate.getDay(); thismonth=todayDate.getMonth(); thisdate=todayDate.getDate(); thisyear=todayDate.getYear(); thisyear = thisyear % 100; thisyear = ((thisyear < 50) ? (2000 + thisyear) : (1900 + thisyear)); if (((thisyear % 4 == 0) && !(thisyear % 100 == 0)) ||(thisyear % 400 == 0)) monthdays[1]++; startspaces=thisdate; while (startspaces > 7) startspaces-=7; startspaces = thisday - startspaces + 1; if (startspaces < 0) startspaces+=7; document.write for (s=0;s<startspaces;s++) { document.write(); } count=1; while (count <= monthdays[thismonth]) { for (b = startspaces;b<7;b++) { linktrue=false; /////displays the date document.write("<br width='30'>"); if (count <= 31) { document.write(monthnames[thismonth]); document.write(" "); } for (c=0;c<linkdays.length;c++) { if (linkdays[c] != null) { if ((linkdays[c][0]==thismonth + 1) && (linkdays[c][1]==count)) { document.write("<a href=\"" + linkdays[c][2] + "\">"); linktrue=true; } } } if (count==thisdate) { document.write("<font color='FF0000'><strong>"); } if (count <= monthdays[thismonth]) { document.write(count); } else { document.write(" "); } if (count==thisdate) { document.write("</strong></font>"); } if (linktrue) document.write("</a>"); document.write; count++; } document.write; document.write("<tr>"); startspaces=0; } document.write("</p>"); // End --> </SCRIPT> </center></body> </html> so here is my "Project http://sw.cs.wwu.edu/~strickk/Project2/project2.html and here are the directions where im stuck at, just right click view source to see the code. I believe what i am doing wrong is where i enter my variables and i dont know how to get an alert message to pop up using an if statement as well as getting the values for the distances to show up correctly directions: 8. Now we will write some JavaScript to validate the input. We don’t want the user to be able to enter the same origin and destination city when they book a ticket. So we will use an if statement to check that. If they have entered the same origin and destination city then we will tell them that by using an alert statement and make them select again. All of your code to validate the input code goes in between the single quotes of the onClick event in the Calculate Fare button. Follow these steps: a) Assign the value of the origin city to a variable called origin Note that the value that gets assigned to origin is actually 0, 60, 90, 120 or 150 (and NOT Bellingham, Everett, Seattle etc.) since the value we gave to the each element of the list was its distance from Bellingham. This will make our lives easier later when we compute the fare. b) Assign the value of the destination city to a variable called destination in a similar fashion. c) Write an if statement that will test whether origin is equal to destination and if it is then do two things. i. Issue an alert message that says Please input different origin and destination cities ii. Stop the execution of the JavaScript code in the onClick event. Use return; as the second statement inside the if statement. Remember to use curly braces to denote that two statements are contained within the if statement. Your if statement will have the following structure to it. if (<put the test you want to do here>) { alert(<put the message here>); return; } //Need a function that sees if the computer has a 2 move forced win, if so take first of those two moves. //and then see if the opponent has a 2 move forced win. if so, then blaock the first of those two moves. // The gameboard array --this holds the game status var gaBoard = [['o', 'o', 'o', 'o', 'o', 'o', 'o'], ['o', 'o', 'o', 'o', 'o', 'o', 'o'], ['o', 'o', 'o', 'o', 'o', 'o', 'o'], ['o', 'o', 'o', 'o', 'o', 'o', 'o'], ['o', 'o', 'o', 'o', 'o', 'o', 'o'], ['o', 'o', 'o', 'o', 'o', 'o', 'o']]; var gcPlayer = "r"; // current player color var gbGameOver = false; //Loading the Gameboard function vLoad() { var strTable, i, j, strID, strOver, strOut, strTitle, strHover, strPush, strArrow; strTable = "<table cellpadding='0' cellspacing='0'>"; //put a row in the table for the title for (i = 0; i < 1; i++) { strTable += "<tr>"; strTitle = "<h1 style= 'color:Orange; font-family:Broadway'>Connect Four</h1>"; //put in the title strTable += strTD(7, strTitle); strTable += "</tr>"; // Buttons area strTable += "<tr>"; strTable += strTD(4, strButton("New Game", "vReset()")); strTable += strTD(3, strButton("Computer Move", "vComputerMove()")); strTable += "</tr>"; } //Arrows Row strTable += "<tr>"; //put in the columns for (j = 0; j < 7; j++) { strID = "img" + j; strHover = "vHover(\"" + strID + "\")"; strPush = "vPush(\"" + strID + "\"," + j + ")"; strArrow = "vArrow(\"" + strID + "\")"; strTable += strTD(1, strImage("arrow.jpg", strID, strPush, strHover, strArrow)); } strTable += "</tr> <tr><td colspan='7'><hr/></td></tr>"; //put a row in the table for the gameboard for (i = 5; i >= 0; i--) { strTable += "<tr>"; //put in the columns for (j = 0; j < 7; j++) { strID = "img" + i + j; strTable += strTD(1, strImage("open.jpg", strID, "", "", "")); } strTable += "</tr>"; } //put a row in the table for the text area for (i = 0; i < 1; i++) { strTable += "<tr>"; strTable += strTD(7, strTextArea(16, 66)); strTable += "</tr>"; } strTable += "</table>"; frm1.innerHTML = strTable; } //*************************************************************************************************** //Functions for Modifying controls function vHover(strID) { document.getElementById(strID).src = "hover.jpg"; } function vArrow(strID) { document.getElementById(strID).src = "arrow.jpg"; } function vMakeRed(strID) { document.getElementById(strID).src = "red.jpg"; } function vMakeBlack(strID) { document.getElementById(strID).src = "black.jpg"; } function vMakeOpen(strID) { document.getElementById(strID).src = "open.jpg"; } function iTopSlot(iCol) { var iRow, iCol; iRow = 0; while ( (iRow < 6) && (gaBoard[iRow][iCol] != 'o')) iRow++; return iRow; } function vPush(strID, iCol) { var iRow, iCol; document.getElementById(strID).src = "push.jpg"; /* if (gbGameOver) { return 0; } */ // see if we can drop a piece into the selected column if (gaBoard[5][iCol] == 'o') { iRow = iTopSlot(iCol); gaBoard[iRow][iCol] = gcPlayer; strID = "img" + iRow + iCol; // switch players if (gcPlayer == "r") { vMakeRed(strID); if (bWinner(gcPlayer)) { alert(gcPlayer + " has won the game."); frm1.taOutput.value += gcPlayer + " has won the game."; gbGameOver = true; } gcPlayer = "b"; } else { vMakeBlack(strID); if (bWinner(gcPlayer)) { frm1.taOutput.value += gcPlayer + " has won the game."; alert(gcPlayer + " has won the game."); gbGameOver = true; } gcPlayer = "r"; } } else { frm1.taOutput.value += "That column is full - try again.\n"; } } function bWinner(cPlayer) { var iCol, iRow; //Horizontal Win for (iRow = 0; iRow < 6; iRow++) { for (iCol = 0; iCol < 4; iCol++) { if ((gaBoard[iRow][iCol] == cPlayer) && (gaBoard[iRow][iCol + 1] == cPlayer) && (gaBoard[iRow][iCol + 2] == cPlayer) && (gaBoard[iRow][iCol + 3] == cPlayer)) return true; } } //Verticle Win for (iRow = 0; iRow < 3; iRow++) { for (iCol = 0; iCol < 7; iCol++) { if ((gaBoard[iRow][iCol] == cPlayer) && (gaBoard[iRow + 1][iCol] == cPlayer) && (gaBoard[iRow + 2][iCol] == cPlayer) && (gaBoard[iRow + 3][iCol] == cPlayer)) return true; } } //diagonal win Positive Slope for (iRow = 0; iRow < 3; iRow++) { for (iCol = 0; iCol < 4; iCol++) { if ((gaBoard[iRow][iCol] == cPlayer) && (gaBoard[iRow + 1][iCol + 1] == cPlayer) && (gaBoard[iRow + 2][iCol + 2] == cPlayer) && (gaBoard[iRow + 3][iCol + 3] == cPlayer)) return true; } } //diagonal win Negative Slope for (iRow = 3; iRow < 6; iRow++) { for (iCol = 0; iCol < 4; iCol++) { if ((gaBoard[iRow][iCol] == cPlayer) && (gaBoard[iRow - 1][iCol + 1] == cPlayer) && (gaBoard[iRow - 2][iCol + 2] == cPlayer) && (gaBoard[iRow - 3][iCol + 3] == cPlayer)) return true; } } return false; } function vComputerMove(){ var iRow,iCol,iWinCol; //Try to win iWinCol = -1; iLoseCol = -1; for(iCol = 0; iCol < 7; iCol++) { iRow = iTopSlot(iCol) if(iRow < 6) { gaBoard[iRow][iCol] = gcPlayer; if(bWinner(gcPlayer)) iWinCol = iCol; gaBoard[iRow][iCol] = 'o'; } } if (iWinCol > -1) { vPush("img" + iWinCol, iWinCol); } //Try to Block if (gcPlayer == 'b') { for (iCol = 0; iCol < 7; iCol++) { iRow = iTopSlot(iCol) if (iRow < 6) { gaBoard[iRow][iCol] = 'r'; if (bWinner('r')) iLoseCol = iCol; gaBoard[iRow][iCol] = 'o'; } } } else if (gcPlayer == 'r') { for (iCol = 0; iCol < 7; iCol++) { iRow = iTopSlot(iCol) if (iRow < 6) { gaBoard[iRow][iCol] = 'b'; if (bWinner('b')) iLoseCol = iCol; gaBoard[iRow][iCol] = 'o'; } } } if (iLoseCol > -1) { vPush("img" + iLoseCol, iLoseCol); } else vRandomMove(); } function vRandomMove() { var iRandom, iRow; iRow = 6; while (iRow == 6) { iRandom = (Math.floor(Math.random() * 7)); iRow = iTopSlot(iRandom); } vPush("img" + iRandom, iRandom); } function vReset() { for (i = 5; i >= 0; i--) { for (j = 0; j < 7; j++) { gaBoard[i][j] = 'o'; strID = "img" + i + j; vMakeOpen(strID); } } frm1.taOutput.value = ""; gcPlayer = "r"; } //*************************************************************************************************** //Functions for making form controls //Button Maker function strButton(strValue, strOnclick) { return "<input type='button' value='" + strValue + "' onclick='" + strOnclick + "' />" } //Image Maker function strImage(strSource, strID, strOnclick, strMouseOver, strMouseOut) { var strReturn; strReturn = "<img src='" + strSource + "' id='" + strID + "' onclick='" + strOnclick + "' "; strReturn += "onmouseover='" + strMouseOver + "' onmouseout='" + strMouseOut + "' />" return strReturn; } //TD Maker function strTD(iColspan, strContent) { return "<td colspan='" + iColspan + "'>" + strContent + "</td>"; } //Text Area Maker function strTextArea(iRows, iCol) { var strReturn; strReturn = "<textarea id='taOutput' "; strReturn += "' rows= '" + iRows + "' cols='" + iCol + "'readonly='readonly'>"; strReturn += "</textarea>"; return strReturn; } 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 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 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 there, I need to validate three textboxes and it will validate for numbers. How should I change my code to validate three textboxes? Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head> <title>Untitled Page</title> <script type='text/javascript' language="javascript"> var validPhoneChar = "+"; // Minimum no of digits in an international phone no. var minDigitsInPhoneNumber = 10; function isInteger(s) { var i; for (i = 0; i < s.length; i++) { // Check that current character is a number. var c = s.charAt(i); if (((c < "0") || (c > "9"))) return false; } // All characters are numbers. return true; } function stripCharsInBag(s, bag) { var i; var returnString = ""; // Search through string's characters one by one. // If character is not in bag, append to returnString. for (i = 0; i < s.length; i++) { // Check that current character isn't whitespace. var c = s.charAt(i); if (bag.indexOf(c) == -1) returnString += c; } return returnString; } function checkRequirements(strPhone) { if(strPhone.indexOf("+") > 1) return false; s = stripCharsInBag(strPhone,validPhoneChar); return (isInteger(s) && s.length >= minDigitsInPhoneNumber); } function ValidateForm() { var Phone = document.getElementById("Text1"); //var Phone1 = document.getElementById("Text23"); if ((Phone.value == null)||(Phone.value == "")) //if match failed { alert("Please Enter your Phone Number."); Phone.focus(); return false; } /*if ((Phone1.value == null)||(Phone1.value == "")) //if match failed { alert("Please Enter your Phone Number0."); Phone.focus(); return false; }*/ if (checkRequirements(Phone.value) == false) { alert("Please Enter a Valid Phone Number."); Phone.value = ""; Phone.focus(); return false; } else alert("YAY!"); return true; } function NotAllowSpace() { // Get the ASCII value of the key that the user entered var key = window.event.keyCode; // Verify if the key entered was a Space if ( key == 32 ) { // If it was, then dispose the key and continue with entry window.event.returnValue = null; alert("Invalid,Please check") } else // If it was not, then allow the entry to continue return; } </script> </head> <body> <label>Office Telephone:</label> <input id="Text1" type="text" onkeydown = "return (event.keyCode != 32)"/><br /> <input id="Button1" type="button" value="button" onclick="return ValidateForm();" /><br /> </body> </html> I need to use Javascript to validate 3 textboxes, whereby the users can only key in numbers (because they are phone numbers related fields). If any of the textbox is empty, display an alert message to show which textbox is empty. I do not want to show many alert messages to show that, for example, text1 and text2 are empty, it will show two alert messages. I would need to show one "summarized" alert message instead. Next, check if the textbox matches the pattern (which is to check if it has the skeleton of a phone number). If it is, show an alert message that it is alright. Else, show that it does not match. I am trying to validate textboxes on my form. I got everything but phone number. I have three different textboxes. One for area, one for first three, and last one for last 4numbers. everything just need to be digit numbers I guess. What is REGEX expression should be for those three different area?
Arrrgggghhhhhhhhh - help.... - LOL Now I've got that over with, hope someone can help. Am just learning regular expressions and am trying to validate UK format telephone numbers (have had an extensive look on the web and only examples I can find are US tests). Anyway, I want to learn to do it myself. UK phone number rules a Must start with a 0 in position 1 Next 2 to 4 characters must be a number Next character can be a space or a dash Next 6 to 9 characters can be a number, space or dash only Anyway, as I say, am new to regular expressions and trying to learn so I tried to write the expression to fit the rules above - see below: Code: ^[0]{1}\d{2,4}\s|-{1}\d|\s|-{6,9}$ My logic (for what it's worth - LOL) tells me this should work, but it doesn't - it accepts letters as well - which I really don't understand yet. Anyway - hope someone can help. Thanks Dominic |