Web Source2014. 9. 22. 21:40

네이버에서는 검색이 어려운 블로그입니다. 구글검색을 이용해 주세요.



컴퓨터의 브라우저 종류 확인

http://www.useragentstring.com/pages/useragentstring.php


<script>
function get_browser_info(){
var ua=navigator.userAgent,tem;
var M=ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i)||[];
if(/trident/i.test(M[1])){tem=/\brv[ :]+(\d+)/g.exec(ua)||[];return {name:'MSIE',version:(tem[1]||'')};}   
if(M[1]==='Chrome'){tem=ua.match(/\bOPR\/(\d+)/);if(tem) return {name:'Opera',version:tem[1]};}   
M=M[2]?[M[1],M[2]]:[navigator.appName,navigator.appVersion, '-?'];
if(tem=ua.match(/version\/(\d+)/i)) M.splice(1,1,tem[1]);
return {name:M[0],version:M[1]};
}

var browser=get_browser_info();
console.log(browser.name);
console.log(browser.version);

var browser=get_browser_info();
if(browser.name=='Firefox'&&browser.version<=28) {
  var root=document.documentElement;
  root.className+=" firefox28";
}
</script>

========================================================================================


http://stackoverflow.com/questions/10964966

var div = document.createElement("div");

div.innerHTML = "<!--[if lte IE 9]><i></i><![endif]-->";

var oldie = (div.getElementsByTagName("i").length == 1);//IE9 이하


IE와 버전별 체크하기(11버전까지 체크)
var isIE=(/(?:MSIE |Trident\/.*; rv:)(\d+)/.exec(navigator.userAgent))?Number(RegExp.$1):0;
if(isIE) // IE 인지 체크한다.
if(!isIE) // IE 가 아닌지 체크한다.
if(isIE==8) // IE8 인지 체크한다.
if(isIE>7) // IE8 이상인지 체크한다.
if(isIE&&isIE<9) // IE8 이하인지 체크한다.
if(isIE>7&&isIE<11) // IE8 이상 10 이하인지 체크한다.

IE12버전까지 체크
navigator.userAgent.indexOf("MSIE ") > 0 || navigator.userAgent.indexOf("Trident") > 0 || navigator.userAgent.indexOf("Edge") > 0

Default string of IE 12:
Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36 Edge/12.0


========================================================================================


참고로 Daum.net 의 소스

========================================================================================


Javascript

http://stackoverflow.com/questions/9847580


var isOpera = !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0;

    // Opera 8.0+ (UA detection to detect Blink/v8-powered Opera)

var isFirefox = typeof InstallTrigger !== 'undefined';   // Firefox 1.0+

var isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0;

    // At least Safari 3+: "[object HTMLElementConstructor]"

var isChrome = !!window.chrome && !isOpera;              // Chrome 1+

var isIE = /*@cc_on!@*/false || !!document.documentMode; // At least IE6


========================================================================================


PHP

https://github.com/cbschuld/Browser.php


<?

$agent = $_SERVER["HTTP_USER_AGENT"];

$msie = (strpos($agent, 'MSIE') || strpos($agent, 'Trident')) ? true : false;

if ($msie) {

print "MSIE".PHP_EOL;

} else {

print "not MSIE".PHP_EOL;

}

?>


나머지는 아래에 가서 확인하면 된다.

========================================================================================


모바일 브라우저 종류 확인


Detect Mobile Browsers

Open source mobile phone detection


http://detectmobilebrowsers.com/


========================================================================================


참고

http://www.quirksmode.org/css/condcom.html


<!--[if IE]>

According to the conditional comment this is IE<br />

<![endif]-->

<!--[if IE 6]>

According to the conditional comment this is IE 6<br />

<![endif]-->

<!--[if IE 7]>

According to the conditional comment this is IE 7<br />

<![endif]-->

<!--[if IE 8]>

According to the conditional comment this is IE 8<br />

<![endif]-->

<!--[if IE 9]>

According to the conditional comment this is IE 9<br />

<![endif]-->

<!--[if gte IE 8]>

According to the conditional comment this is IE 8 or higher<br />

<![endif]-->

<!--[if lt IE 9]>

According to the conditional comment this is IE lower than 9<br />

<![endif]-->

<!--[if lte IE 7]>

According to the conditional comment this is IE lower or equal to 7<br />

<![endif]-->

<!--[if gt IE 6]>

According to the conditional comment this is IE greater than 6<br />

<![endif]-->

<!--[if !IE]> -->

According to the conditional comment this is not IE 5-9<br />

<!-- <![endif]-->




<!--[if lte IE 8 ]--> ELSE?
css - Else in HTML conditional for IE

아래의 경우는 IE8 이하버전(구버전)인지
IE9 이상의 버전과 IE 외의 모든 브라우저(신버전)인지 체크한다.

<!--[if lte IE 8]>
    // your style or script
    // this is browsers: IE8 or lower.
<![endif]-->

<!--[if gte IE 9]><!-->
    // your style or script
    // this is all browsers: IE9 or higher, firefox, chrome, etc.
<!--<![endif]-->

<!--[if (gt IE 8)|!(IE)]><!-->
    // your style or script
    // this is all browsers: IE9 or higher, firefox, chrome, etc.
<!--<![endif]-->

========================================================================================


아래 내용들은 옛날 방식이다.
현재 64비트 IE11버전은 아래 방식으로 맞지 않다.

Javascript

// msie, firefox, safari, chrome

function isIE () {

  var myNav = navigator.userAgent.toLowerCase();

  return (myNav.indexOf('msie') != -1) ? parseInt(myNav.split('msie')[1]) : false;

}


if (!isIE()) { 


}


var agt = navigator.userAgent.toLowerCase();
if (agt.indexOf("chrome") != -1) return 'Chrome'; 
if (agt.indexOf("opera") != -1) return 'Opera'; 
if (agt.indexOf("staroffice") != -1) return 'Star Office'; 
if (agt.indexOf("webtv") != -1) return 'WebTV'; 
if (agt.indexOf("beonex") != -1) return 'Beonex'; 
if (agt.indexOf("chimera") != -1) return 'Chimera'; 
if (agt.indexOf("netpositive") != -1) return 'NetPositive'; 
if (agt.indexOf("phoenix") != -1) return 'Phoenix'; 
if (agt.indexOf("firefox") != -1) return 'Firefox'; 
if (agt.indexOf("safari") != -1) return 'Safari'; 
if (agt.indexOf("skipstone") != -1) return 'SkipStone'; 
if (agt.indexOf("msie") != -1) return 'Internet Explorer'; 
if (agt.indexOf("netscape") != -1) return 'Netscape'; 
if (agt.indexOf("mozilla/5.0") != -1) return 'Mozilla'; 


PHP

http://echopx.com/notes/browser-detection-ie-firefox-safari-chrome



  1. <?php
  2. $msie = strpos($_SERVER["HTTP_USER_AGENT"], 'MSIE') ? true : false;
  3. $firefox = strpos($_SERVER["HTTP_USER_AGENT"], 'Firefox') ? true : false;
  4. $safari = strpos($_SERVER["HTTP_USER_AGENT"], 'Safari') ? true : false;
  5. $chrome = strpos($_SERVER["HTTP_USER_AGENT"], 'Chrome') ? true : false;
  6. ?>



  1. <?php
  2. //Firefox
  3. if ($firefox) {
  4. echo 'you are using Firefox!';
  5. echo '<br />';
  6. }
  7.  
  8. // Safari or Chrome. Both use the same engine - webkit
  9. if ($safari || $chrome) {
  10. echo 'you are using a webkit powered browser';
  11. echo '<br />';
  12. }
  13.  
  14. // IE
  15. if ($msie) {
  16. echo '<br>you are using Internet Explorer<br>';
  17. echo '<br />';
  18. }
  19.  
  20. // Not IE and for all other browsers
  21. if (!$msie) {
  22. echo '<br>you are not using Internet Explorer<br>';
  23. echo '<br />';
  24. }
  25.  
  26. // Add inline css
  27. if ($firefox) {
  28. echo '<style type="text/css">';
  29. echo '.mydiv {position:relative; width:100px; height:50px;}';
  30. echo '</style>';
  31. }
  32. ?>




'Web Source' 카테고리의 다른 글

Center a new popup window even on dualscreen with javascript  (0) 2014.10.06
Get Cross Domain iFrame Content  (0) 2014.09.25
iFrame auto resizer  (0) 2014.09.04
Div Zoom iFrame  (0) 2014.09.03
javascript yesterday  (0) 2014.09.03
Posted by 영육치료