JavaScript - Javascript Browser Recognition.
I was wondering if there was any way to determine what browser the remote address is using through JavaScript preferably or any other language and if so how to direct them to another page if they're using a specific browser...
Similar TutorialsGreetings, I am currently using the websites tutorial about browser detection using the navigator. http://www.javascriptkit.com/javatutors/navigator.shtml I am however finding myself unable to detect a pattern in order to learn from. My aim is to use Browser detection to have a CSS file for each browser type, such as Firefox, IE, Opera, Safari and then an overall CSS file if none of the above, to fix numerous flaws. For IE and Firefox using the site's code is all well and good and while I haven't tested it yet I'm wondering how to set up the coding so that it can detect a safari browser. There are lots of slashes and d's and brackets and I do find myself unable to understand their purpose. So if someone can explain how I could do it for Safari I would be very appreciative. Hello, I have a question what is the best way to identify a browser, browser version and OS in javascript. I have try a few scripts but they all fail. This will help me out formating the code for diferent browsers. Thanks Hi, I have 3 functions. I do not know how to have 2 functions recognize the output of an array from the other function. All of this revolves around input(text boxes). What is the array's output? In other words, how do I get the newly added textboxes recognized by the initial functions - what are they called? I have tried adding names like "No. of Hours[1]"; "No. of Hours(1)"; or,"No. of Hours1"; but none of that works. For example, one of the inputs is called "No. of Hours". That is the input textbox on the web page. When the add new rows array is invoked it adds new input textboxes and the new element is Code: el.type = 'text'; el.name = 'No. of Hours' + iteration; el.id = 'No. of Hours' + iteration; el.size = 7; cellRight.appendChild(el); What is this new input/element called so that I can refer to it for the coded function shown below? The first function provides validation for user input. Code: function checkQuarters( fld ) { var val = parseFloat(fld.value); if ( isNaN(val) || ( val*4 != Math.floor(val*4) ) ) { alert("Value must be a numeric and a multiple of 0.25"); return false; } return true; } </script> The input for the above function is Code: <td> <form style="width: 5px; height: 1px;"> <input type="text" name="No. of Hours" id="No. of Hours" style="width: 70px;" onblur="checkQuarters(this);" /> </form></td> The array outputs added textboxes thusly, Code: new_rows[row_count]['cell3']=sel; var cellRight = row.insertCell(3); var el = document.createElement('input'); el.type = 'text'; el.name = 'No. of Hours' + iteration; el.id = 'No. of Hours' + iteration; el.size = 7; cellRight.appendChild(el); new_rows[row_count]['cell']=el; row_count++; The other function uses a JQuery for a datepicker. Code: <script type="text/javascript"> $(function() { $("#startdate").datepicker(); $("#enddate").datepicker(); }); </script> The input is this. Code: <td><input style="width: 70px" type="text" id="startdate"></td> <td><input style="width: 70px" type="text" id="enddate"></td> I am lost on this and could really use some help and guidance. Thanks, John Hi, I want to write a javascript program which will redirect the user from a welcome page to an an intro page when a cookie is found. If there are not cookies found, the welcome page is loaded but a cookie is written so that next time the user visits the page, he will be redirected to the intro page automatically. This program would allow only new visitor to view the welcome page and other visitors to skip the welcome page to be brought to the intro page right away. I am a newbie and here is the code which I have though of so far. Can someone expand on it? Thanks The Apprentice Code: window.onload = pageInit; function pageInit(){ var visited = ""; if (document.cookie !=""){ window.location = "introPage.htm"; } else{ setCookie(); } function setCookie(){ document.getElementById("click").onclick = cookie; var expireDate = new Date(); expireDate.setMonth(expireDate.getMonth() + 6); Hi, I have a dynamic JS table and the user can add several rows then populate rows with data. There are 4 columns in table. First row, first two columns have JQuery calendar. Third column has populated select list. Fourth column, first row has JS function to ensure that user enters integer/decimal with corresponding alert for incorrect entry. Two things I want to do: 1. Populate added rows with JQuery calendars and integer/decimal alert. 2. Capture added rows and data from user entries so that information can be sent to database via ColdFusion programming. The following is the js code I am using: For the datepicker I linked to an in-house URL so this is the function - Code: $(function() { $("#startdate").datepicker(); $("#enddate").datepicker(); $("#RcompStart").datepicker(); $("#RcompEnd").datepicker(); }); </script> The objects (inputs) for the above are Code: <td><input style="width: 70px" type="text" id="startdate"></td> <td><input style="width: 70px" type="text" id="enddate"></td> For the numeric alert the function is Code: <script type="text/javascript"> function checkQuarters( fld ) { var val = parseFloat(fld.value); if ( isNaN(val) || ( val*4 != Math.floor(val*4) ) ) { alert("Value must be a numeric and a multiple of 0.25"); return false; } return true; } </script> The object (input) for the above is Code: <td><p> <form style="width: 5px; height: 1px;"> <input type="text" name="No. of Hours" id="No. of Hours" style="width: 70px;" onblur="checkQuarters(this);" /> </form> </td> And to add and remove rows the function is Code: <script language="Javascript" type="text/javascript"> /*<![CDATA[*/ var new_rows=new Array(); var row_count=0; function addRow() { var tbl = document.getElementById('ReqDtTbl'); new_rows[row_count]=new Array(); var lastRow = tbl.rows.length; var iteration = lastRow; if (lastRow>7){ return;} var row = tbl.insertRow(lastRow); var cellLeft = row.insertCell(0); var textNode = document.createElement('input'); textNode.size = 7; textNode.name = 'startdate' + iteration; cellLeft.appendChild(textNode); new_rows[row_count]['cell']=textNode; var cellRight = row.insertCell(1); var el = document.createElement('input'); el.type = 'text'; el.name = 'enddate' + iteration; el.id = 'enddate' + iteration; el.size = 7; new_rows[row_count]['cell2']=el; cellRight.appendChild(el); // the last cell! var cellRightSel = row.insertCell(2); var sel = document.createElement('select'); sel.name = 'TypeHrs' + iteration; sel.options[0] = new Option('-Select-', '""'); sel.options[1] = new Option('Comp Time', 'Comp Time'); sel.options[2] = new Option('Credit Hrs', 'Credit Hrs'); sel.options[3] = new Option('Overtime', 'Overtime'); sel.options[4] = new Option('Rel Comp', 'Rel Comp'); cellRightSel.appendChild(sel); new_rows[row_count]['cell3']=sel; var cellRight = row.insertCell(3); var el = document.createElement('input'); el.type = 'text'; el.name = 'No. of Hours' + iteration; el.id = 'No. of Hours' + iteration; el.size = 7; cellRight.appendChild(el); new_rows[row_count]['cell']=el; row_count++; } function removeRow() { // grab element again var tbl = document.getElementById('ReqDtTbl'); // grab length var lastRow = tbl.rows.length; // delete last row if there is more than one row if (lastRow > 2) tbl.deleteRow(lastRow - 1); } /*]]>*/ </script> The buttons for this function are Code: <input type="button" value="Add a row" onclick="addRow('ReqDtTbl',5)";/> <input type="button" value="Remove a row" onclick="removeRow();" /> That's it. Thanks - John Hello! I am trying to find a script that allows you to open multiple browser tabs and then close each of those tabs, either one by one or all at once. Does anyone know how to do this please? Thanks so much for your help. I have code that I've been using for awhile now that will automatically log users off my site after a period of time. It works great using a 32 bit browser but not at all with a 64 bit browser. For the life of me I can't figure this out. <script type='text/javascript'> var secondsRemaining = 30; var mhcTimer; function countDown() { secondsRemaining -= 1; if (secondsRemaining <= 0) { secondsRemaining = 0; window.location='login.aspx'; } } function startAutoLogoff() { if (mhcTimer) { return false; } else { mhcTimer = setInterval('countDown();', 1000); } } startAutoLogoff(); </script> Dear all, can somebody help me with browser compatibility and this code. Working fine in Opera and Firefox, but do not working in Internet Explorer and Chrome. With one form working fine in every browser, but when I put second form it stops to work in Explorer and Chrome. Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <HTML> <HEAD> <META http-equiv=Content-Type content="text/html; charset=UTF-8"> <SCRIPT type="text/javascript"> function showDiv(divIndex) { var f=document.forms[0]; var d=f.getElementsByTagName('div'); for(i=0;i<d.length;i++)d[i].style.display='none' d[divIndex].style.display = 'block'; } </SCRIPT> </HEAD> <BODY> <form> <select onchange="showDiv(this.value); "> <option value="0" selected>option 1</option> <option value="1">option 2</option> <option value="2">option 3</option> </select> <div style="display:block;"><form action="001.htm" method="get" > Your state<br> <select name="statecode" id="statecode"> <option value="">Choose State for option 1...</option> <option value="AK">Alaska</option> <option value="AL">Alabama</option> <option value="AR">Arkansas</option> </select> <input type="submit" name="search" value="Get Quotes" /> </form></div> <div style="display:none;"><form action="002.htm" method="get" > Your state<br> <select name="statecode" id="statecode"> <option value="">Choose State for option 2...</option> <option value="AK">California</option> <option value="AL">Colorado</option> <option value="AR">Connecticut</option> </select> <input type="submit" name="search" value="Get Quotes" /> </form></div> <div style="display:none;"><form action="003.htm" method="get" > Your state<br> <select name="statecode" id="statecode"> <option value="">Choose State for option 3...</option> <option value="AK">Massachusetts</option> <option value="AL">Maryland</option> <option value="AR">Maine</option> </select> <input type="submit" name="search" value="Get Quotes" /> </form></div> </form> </BODY></HTML> I'm trying to use SmoothGallery 2.1 on my website as a featured box. I tried opening the demos provided with the code in all browsers to make sure it was compatible and it showed fine in them all. I copied the javascript onto my site and I'm able to show the gallery. However in Chrome and Internet Explorer it shows fine, but Firefox the images are spread vertically down my site and the javascript gallery box doesn't show. I don't understand why this is an issue because it shows fine opening the demo pages and the javascript code and css is a straight copy from the folder :S Can anyone help me out? Website I'm having the issue on is www.deewon.com -Thanks Hi I am a new bie to Javascript programming. We have a scenario to launch a new browser window for a given HTML. I have the following approaches : Approach 1: my_window = window.open("", "report"); my_window.document.open(); my_window.document.write("<HTML> <BODY> HI </BODY></HTML>"); my_window.document.close(); Approach 2: var newWindow = window.open("", "report"); newWindow.document.body.innerHTML = "<HTML> <BODY> HI </BODY></HTML>"; Could anyone sugges Which is the correct approach ? Our requirement is to have this code to work in any browser? Thanks Hello All, I'm working on a image slider, which will slide left to right and vice versa on mouser over event. the images are dynamically loaded from the database using ASP script. I use mootools.svn.js for the sliding implementation. and Ajax to pass the id of the image to another page as a query string. this is implemented in a Code: onclick="getValue('<%= id %>')" event. This works fine in IE8, but when I test in Firefox 3.6 and Chrome the onclick event doesn't work. when I comment the mootools.svn.js, the onclick event get fired. what causes this. is their any solution? now my development has come to a grinding halt because of this. Please help <%@ Import Namespace="System" %> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.SqlClient"%> <%@ Import Namespace="System.Configuration" %> <%@ Import Namespace="System.Collections" %> <%@ Import Namespace="System.Web" %> <%@ Import Namespace="System.Web.Security" %> <%@ Import Namespace="System.Web.UI" %> <%@ Import Namespace="System.Web.UI.WebControls" %> <%@ Import Namespace="System.Web.UI.WebControls.WebParts" %> <%@ Import Namespace="System.Web.UI.HtmlControls" %> <%@ Import Namespace="System.Text" %> <%@ Page Language="C#" AutoEventWireup="true" CodeFile="slider.aspx.cs" Inherits="slider" %> <!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 runat="server"> <title>Untitled Page</title> <script language="javascript" type="text/javascript"> //GETS THE IMAGE ID FROM function getValue(val) { alert(val); showHint(val); //document.form1.newval1.value=val; } var xmlhttp=null; //xmlhttp variable //Ajax function make_httpRequest(){ if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else if (window.ActiveXObject) { // code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } else { alert("Your browser does not support XMLHTTP!"); return; } } //Bind the query string as a URL function request_url(url){ url=url+"&sid="+Math.random(); xmlhttp.open("GET",url,false); xmlhttp.send(null); } //BIND THE IMAGE ID TO THE QUERY STRING VARIABLE TO THE url variable function showHint(val) { make_httpRequest(); var url = "Test.aspx?prodid="+ val; request_url(url); } </script> <style type="text/css"> <!-- .slider_con { height: 125px; width: 889px; } .slider_content { height: 125px; width: 889px; float: left; overflow: hidden; position:relative; } .image_con { float: left; height: 125px; width: 23px; } #maiin_container{ width: 889px; height: 125px; overflow: auto; overflow-x:hidden; overflow-y:hidden; float:left; } .main-content { width: 889%; height: 125px; } .section{ margin:0 0 0 0; float:left; } --> </style> <style type="text/css"> <!-- a { font-family: sans-serif; font-size: 15px; color: #666767; } a:link { text-decoration: none; } a:visited { text-decoration: none; color: #666767; } a:hover { text-decoration: none; color: #666767; } a:active { text-decoration: none; color: #666767; } .style1 { color: #A0A0A0 } --> </style> </head> <script type="text/javascript" src="mootools.svn.js"></script> <script type="text/javascript"> window.addEvent('domready', function(){ var scroll2 = new Scroller('maiin_container', {area: 100, velocity: .12}); // container $('maiin_container').addEvent('mouseover', scroll2.start.bind(scroll2)); $('maiin_container').addEvent('mouseout', scroll2.stop.bind(scroll2)); }); </script> <body> <form id="form1" runat="server"> <div class="slider_con"> <div class="image_con section"> </div> <div id="maiin_container"> <div class="main-content" id="Div1"> <% string connectionString = @"Data Source=174.37.88.148;Initial Catalog=lalith_db;uid=lalitha_jew;pwd=lalitha1234"; string query = "SELECT prod_id, prod_itemcode, prod_title, prod_thumbnailimage FROM dbo.products WHERE cat_id="+22+"and prod_topfive = 'yes' UNION SELECT prod_id, prod_itemcode, prod_title, prod_thumbnailimage FROM dbo.products WHERE cat_id="+22+"and prod_topfive = 'no'"; SqlConnection conn = new SqlConnection(connectionString); try { conn.Open(); } catch(Exception ex) { conn.Close(); } SqlDataReader reader; using (reader = new SqlCommand(query, conn).ExecuteReader()) { if (reader.HasRows) { while (reader.Read()) { int id = reader.GetInt32(reader.GetOrdinal("prod_id")); string prod_itemcode = reader.GetString(reader.GetOrdinal("prod_itemcode")); string prod_title = reader.GetString(reader.GetOrdinal("prod_title")); string prod_thumbnailimage = reader.GetString(reader.GetOrdinal("prod_thumbnailimage")); int i = prod_thumbnailimage.IndexOf('b'); string url = prod_thumbnailimage.Substring(i); %> <div class="section"> <a href="#" id='<%= id %>' onclick='getValue(<%= id %>)'><img id="img" src='<%= url %>' alt='<%= prod_title %>' /></a> </div> <% } } } %> </div> </div> </div> </form> </body> </html> Hi, I have a requirement where, on a link, when the user clicks, the app should copy all browser favorites and write to a db (table that has two columns, one with fav name and one col for the website link). Thoughts on how to get this done ? How can I read the the browser favorites from a javascript ? Thanks, Deepna I am in the process of developing a form for the company intranet and i've recently added in code to capture the enter key event to prevent the page from automatically submitting. Along with this, i added code to move the focus to the next element in the tab index. When used in IE, the code works perfectly, but when i use it in firefox or chrome the focus jumps to the same box every time. I don't know what i'm doing wrong am i'm hoping someone can help me figure this out. You can test the page at http://implicitarts.com/fandfwork/Lo...l/default.aspx To start, go to the box for duty amount or freight charges and press enter The following code is what I used to handle this event. Code: function handleKeyPress2(e,control) { var evt = e ? e : window.event; var bt = control.id; if (bt) { if (evt.keyCode == 13) { //bt.click(); jumptoNext(control, e); stopEvent(e); return false; } } } function jumptoNext(field, event) { for (i = 0; i < field.form.elements.length; i++) if (field.form.elements[i].tabIndex == field.tabIndex + 1) { field.form.elements[i].focus(); if (field.form.elements[i].type == "text") field.form.elements[i].select(); break; } } function stopEvent(e) { if (e.stopPropagation) e.stopPropagation(); else e.cancelBubble = true; if (e.preventDefault) e.preventDefault(); else e.returnValue = false; } I have found this Alarm Clock from JavaScript Kit and when the alarm time is reached it redirects to the URL entered. I would like to keep the alarm clock running, have it open a new window for the entered URL such as (Target="Blank") in HTML. Can someone help? var jsalarm={ padfield:function(f){ return (f<10)? "0"+f : f }, showcurrenttime:function(){ var dateobj=new Date() var ct=this.padfield(dateobj.getHours())+":"+this.padfield(dateobj.getMinutes())+":"+this.padfield(dateo bj.getSeconds()) this.ctref.innerHTML=ct this.ctref.setAttribute("title", ct) if (typeof this.hourwake!="undefined"){ //if alarm is set if (this.ctref.title==(this.hourwake+":"+this.minutewake+":"+this.secondwake)){ window.location=document.getElementById("musicloc").value } ok, so i am working on a type of Option Box that is heavily formatted with CSS and animated using JS $fx() The $fx framework works fine on all browsers, and i have only used fairly simple code, and yet my page functions perfectly on Chrome and Safari. but will not work in Firefox or IE (Firefox does nothing, and IE has a couple of css issues and doesnt work either...) http://calumk.com/else/blogpoststuff...ng_Option_Box/ if anyone could help me i would really appreciate it. (obviously view in Chrome or safari to see how it is meant to respond) Hi, I'm doing something wrong, I want my script to execute when the browser window opens, can someone please help me? Code: <p><iframe id="myFrame" style="display: none;" width="500" height="300"></iframe> <script type="text/javascript">// <![CDATA[ window.onload=openpdf(); type="text/javascript">// <![CDATA[ function openPdf() { var omyFrame = document.getElementById("myFrame"); omyFrame.style.display="block"; omyFrame.src = "myFile.pdf"; } // ]]></script> Does anyone have any idea how to imitate browser zoom with javascript? I know you are not allowed to control browser's zoom capabilities, but perhaps there's a way to change all content dimensions with javascript? In firefox, when you press ctrl+, the whole page resizes appropriately, even background images. With this imitation JS zoom, background images would not zoom since there is no scale size numer or anything like that in CSS. It would simply be cool to have a script that resizes everything on the page. That way, you can design highdefinition content that fits a 1280 * 960 browser frame, but can zoom out for smaller resolutions (1024 or 800). That's be neato!! Any ideas? Anyone know a script? I am trying to use JavaScript to manipulate the appearance of a web browser. (1) Initially I need to identify and save the current browser settings (e.g. position, height, width, caption on or off, menubar on or off, border on or off). (2) Then I need to change the appearance of the browser to full screen, no border, no caption, no status bar, no menubar). (3) Finally, I need to return the browser to the initial settings using the settings saved at the beginning. I am a novice at JavaScript and am having a difficult time locating details of the language that permit me to accomplish my objectives. John Chapman jchapman@onlinecbt.com Hi to everyone! Script first: Code: var allowscroll = 0 //Mouse scroll ____________________________________________________________________________________ function handle(delta) { if(allowscroll == 1){ if (delta < 0){ simgs1dest_x -= 30 } else{ simgs1dest_x += 30 } } if(allowscroll == 2){ if (delta < 0){ textdest_y -= 30 } else{ textdest_y += 30 } } } function wheel(event){ var delta = 0; if (!event) event = window.event; if (event.wheelDelta) { delta = event.wheelDelta/120; } else if (event.detail) { delta = -event.detail/3; } if (delta) handle(delta); if (event.preventDefault) event.preventDefault(); event.returnValue = false; } if (window.addEventListener){ window.addEventListener('DOMMouseScroll', wheel, false); window.onmousewheel = document.onmousewheel = wheel; } I'm using this script to scroll two divs, which each activates self scrolling onMouseOver and onMouseOut deactivate scrolling by setting allowscroll varible to 0. And everything works fine, but this script doesn't allow to scroll browser entire page! So is there a script wich will scroll browser page when allowscroll is equal to 0? |