자바 스크립트에서는 아래 함수를 사용한다.
function getBrowser() {
var agent = navigator.userAgent;
var result = "unknown";
if (agent == null) {
} else if (agent.indexOf("MSIE 6.0") > -1) {
result = "ie6";
} else if (agent.indexOf("MSIE 7.0") > -1) {
result = "ie7";
} else if (agent.indexOf("MSIE 8.0") > -1) {
result = "ie8";
} else if (agent.indexOf("Firefox") > -1) {
result = "firefox";
} else if (agent.indexOf("Opera") > -1) {
result = "opera";
} else if (agent.indexOf("Chrome") > -1) {
result = "chrome";
} else if (agent.indexOf("Safari") > -1) {
result = "safari";
}
return result;
}
var agent = navigator.userAgent;
var result = "unknown";
if (agent == null) {
} else if (agent.indexOf("MSIE 6.0") > -1) {
result = "ie6";
} else if (agent.indexOf("MSIE 7.0") > -1) {
result = "ie7";
} else if (agent.indexOf("MSIE 8.0") > -1) {
result = "ie8";
} else if (agent.indexOf("Firefox") > -1) {
result = "firefox";
} else if (agent.indexOf("Opera") > -1) {
result = "opera";
} else if (agent.indexOf("Chrome") > -1) {
result = "chrome";
} else if (agent.indexOf("Safari") > -1) {
result = "safari";
}
return result;
}
자바에서는 아래 메소드를 사용한다.
package com.dimdol.util;
import javax.servlet.http.HttpServletRequest;
public final class WebUtils {
private WebUtils() {
}
public static String getBrowser(HttpServletRequest request) {
String agent = request.getHeader("User-Agent");
String result = "unknown";
if (agent == null) {
} else if (agent.indexOf("MSIE 6.0") > -1) {
result = "ie6";
} else if (agent.indexOf("MSIE 7.0") > -1) {
result = "ie7";
} else if (agent.indexOf("MSIE 8.0") > -1) {
result = "ie8";
} else if (agent.indexOf("Firefox") > -1) {
result = "firefox";
} else if (agent.indexOf("Opera") > -1) {
result = "opera";
} else if (agent.indexOf("Chrome") > -1) {
result = "chrome";
} else if (agent.indexOf("Safari") > -1) {
result = "safari";
}
return result;
}
}
import javax.servlet.http.HttpServletRequest;
public final class WebUtils {
private WebUtils() {
}
public static String getBrowser(HttpServletRequest request) {
String agent = request.getHeader("User-Agent");
String result = "unknown";
if (agent == null) {
} else if (agent.indexOf("MSIE 6.0") > -1) {
result = "ie6";
} else if (agent.indexOf("MSIE 7.0") > -1) {
result = "ie7";
} else if (agent.indexOf("MSIE 8.0") > -1) {
result = "ie8";
} else if (agent.indexOf("Firefox") > -1) {
result = "firefox";
} else if (agent.indexOf("Opera") > -1) {
result = "opera";
} else if (agent.indexOf("Chrome") > -1) {
result = "chrome";
} else if (agent.indexOf("Safari") > -1) {
result = "safari";
}
return result;
}
}
Ruby on Rails에서는 아래 함수를 사용한다.
module ApplicationHelper
def get_browser
agent = request.env['HTTP_USER_AGENT']
result = "unknown"
if agent.nil?
elsif agent.include?("MSIE 6.0")
result = "ie6"
elsif agent.include?("MSIE 7.0")
result = "ie7"
elsif agent.include?("MSIE 8.0")
result = "ie8"
elsif agent.include?("Firefox")
result = "firefox"
elsif agent.include?("Opera")
result = "opera"
elsif agent.include?("Chrome")
result = "chrome"
elsif agent.include?("Safari")
result = "safari"
end
return result
end
end
def get_browser
agent = request.env['HTTP_USER_AGENT']
result = "unknown"
if agent.nil?
elsif agent.include?("MSIE 6.0")
result = "ie6"
elsif agent.include?("MSIE 7.0")
result = "ie7"
elsif agent.include?("MSIE 8.0")
result = "ie8"
elsif agent.include?("Firefox")
result = "firefox"
elsif agent.include?("Opera")
result = "opera"
elsif agent.include?("Chrome")
result = "chrome"
elsif agent.include?("Safari")
result = "safari"
end
return result
end
end
1 comment:
메뉴 위치가 바뀌어서 보인다는 것이 정확하게 어떤 현상을 지칭하나요? ^^
Post a Comment