{"id":2162,"date":"2011-04-07T20:21:14","date_gmt":"2011-04-07T10:21:14","guid":{"rendered":"http:\/\/mingersoft.com\/blog\/?p=2162"},"modified":"2011-04-07T20:21:14","modified_gmt":"2011-04-07T10:21:14","slug":"use-javascript-to-forward-to-specific-pages-based-upon-browser-version","status":"publish","type":"post","link":"https:\/\/mingersoft.com\/blog\/2011\/04\/use-javascript-to-forward-to-specific-pages-based-upon-browser-version\/","title":{"rendered":"Use JavaScript to Forward to Specific Pages Based Upon Browser Version"},"content":{"rendered":"<p>A slightly more technical article for today.<\/p>\n<p>Today, I was asked by a colleague to come up with a snippet of code that would detect the version of Internet Explorer in use on a computer and then forward the browser to different pages based upon the result. With a bit of help from Google, I cobbled together the following:<\/p>\n<blockquote><p>&lt;!DOCTYPE html PUBLIC &#8220;-\/\/W3C\/\/DTD XHTML 1.0 Transitional\/\/EN&#8221; &#8220;http:\/\/www.w3.org\/TR\/xhtml1\/DTD\/xhtml1-transitional.dtd&#8221;&gt;<br \/>\n&lt;html xmlns=&#8221;http:\/\/www.w3.org\/1999\/xhtml&#8221; lang=&#8221;en&#8221; xml:lang=&#8221;en&#8221;&gt;<br \/>\n&lt;head&gt;<br \/>\n&lt;title&gt;&lt;\/title&gt;<br \/>\n&lt;script language=&#8221;JavaScript&#8221; type=&#8221;text\/javascript&#8221;&gt;<br \/>\nfunction msieversion()<br \/>\n{<br \/>\nvar ua = window.navigator.userAgent<br \/>\nvar msie = ua.indexOf ( &#8220;MSIE &#8221; )<\/p>\n<p>if ( msie &gt; 0 ) \u00a0 \u00a0 \u00a0\/\/ If Internet Explorer, return version number<br \/>\nreturn parseInt (ua.substring (msie+5, ua.indexOf (&#8220;.&#8221;, msie )))<br \/>\nelse \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \/\/ If another browser, return 0<br \/>\nreturn 0<br \/>\n}<br \/>\n&lt;\/script&gt;<br \/>\n&lt;script language=&#8221;JavaScript&#8221; type=&#8221;text\/javascript&#8221;&gt;<\/p>\n<p>if (msieversion() &lt;= 7)<br \/>\n{<br \/>\nwindow.location=&#8221;http:\/\/google.com.au&#8221;;<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nwindow.location=&#8221;http:\/\/bing.com&#8221;;<br \/>\n}<br \/>\n&lt;\/script&gt;<br \/>\n&lt;\/head&gt;<br \/>\n&lt;body&gt;\t&lt;\/body&gt;<br \/>\n&lt;\/html&gt;<\/p><\/blockquote>\n<p>You can change or extend it to suit your needs or if you just need inspiration to do something else that requires a similar sort of interaction between scripts. You could change it to detect other browsers and their corresponding versions or replace the page redirection script with something else entirely that relies upon the information gathered in the first script.<\/p>\n<p>Sharing is caring!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A slightly more technical article for today. Today, I was asked by a colleague to come up with a snippet of code that would detect the version of Internet Explorer in use on a computer and then forward the browser to different pages based upon the result. With a bit of help from Google, I &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"https:\/\/mingersoft.com\/blog\/2011\/04\/use-javascript-to-forward-to-specific-pages-based-upon-browser-version\/\">Continue reading<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[109,112,18],"tags":[2269,202,2246],"class_list":["post-2162","post","type-post","status-publish","format-standard","hentry","category-browsers","category-internet-explorer","category-technology","tag-internet-explorer","tag-javascript","tag-microsoft","item-wrap"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/mingersoft.com\/blog\/wp-json\/wp\/v2\/posts\/2162","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mingersoft.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mingersoft.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mingersoft.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mingersoft.com\/blog\/wp-json\/wp\/v2\/comments?post=2162"}],"version-history":[{"count":0,"href":"https:\/\/mingersoft.com\/blog\/wp-json\/wp\/v2\/posts\/2162\/revisions"}],"wp:attachment":[{"href":"https:\/\/mingersoft.com\/blog\/wp-json\/wp\/v2\/media?parent=2162"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mingersoft.com\/blog\/wp-json\/wp\/v2\/categories?post=2162"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mingersoft.com\/blog\/wp-json\/wp\/v2\/tags?post=2162"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}