[AS3]as3和js分别判断用户终端的浏览器类型的方法实例
[AS3]as3和js分别判断用户终端的浏览器类型的方法实例
[AS3]as3和js分别判断用户终端的浏览器类型的方法实例
JS的写法
- function getBrowser(){
- var useragent = navigator.userAgent.toLowerCase();
- if(/(.*)maxthon(.*)/.test(useragent)){
- document.write('遨游');
- }
- else if(/(.*)firefox(.*)/.test(useragent)){
- document.write("火狐");
- }
- else if(/(.*)chrome(.*)/.test(useragent)){
- document.write("谷歌");
- }
- else if(/(.*)msie(.*)/.test(useragent)){
- document.write("IE");
- }
- else if(/(.*)mozilla(.*)/.test(useragent) && !/(.*)firefox(.*)/.test(useragent) && !/(.*)chrome(.*)/.test(useragent) && !/(.*)msie(.*)/.test(useragent)){
- document.write("safari");
- }else{
- document.write("cuplayer.com未知");
- }
- return useragent;
- }
AS的写法
- package com.ylsoft.lib{
- import flash.external.ExternalInterface;
- import flash.net.URLRequest;
- import flash.net.navigateToURL;
- public class WebWindow {
- public function openWindow(url:String, window:String="_blank", features:String=""){
- var WINDOW_OPEN_FUNCTION:String = "window.open";
- var myURL:URLRequest = new URLRequest(url);
- var browserName:String = getBrowserName();
- if(getBrowserName() == "maxthon"){
- ExternalInterface.call(WINDOW_OPEN_FUNCTION, url, window, features);
- //navigateToURL(myURL, window);
- }
- //If IE,
- else if(browserName == "firefox"){
- navigateToURL(myURL, window);
- }
- //If Safari
- else if(browserName == "chrome"){
- navigateToURL(myURL, window);
- }
- //If Opera
- else if(browserName == "msie"){
- ExternalInterface.call(WINDOW_OPEN_FUNCTION, url, window, features);
- }
- else if(browserName == "safari"){
- ExternalInterface.call(WINDOW_OPEN_FUNCTION, url, window, features);
- }
- else {
- navigateToURL(myURL, window);
- }
- /*Alternate methodology...
- var popSuccess:Boolean = ExternalInterface.call(WINDOW_OPEN_FUNCTION, url, window, features);
- if(popSuccess == false){
- navigateToURL(myURL, window);
- }*/
- }
- private function getBrowserName():String{
- var browser:String;
- //Uses external interface to reach out to browser and grab browser useragent info.
- var browserAgent:String = ExternalInterface.call("function getBrowser(){return navigator.userAgent.toLowerCase();}");
- // Debug.text += "Browser Info: [" + browserAgent + "]";
- //Determines brand of browser using a find index. If not found indexOf returns (-1).
- if(browserAgent != null && /(.*)maxthon(.*)/.test(browserAgent)) {
- browser = "maxthon";
- }
- else if(browserAgent != null && /(.*)firefox(.*)/.test(browserAgent)){
- browser = "firefox";
- }
- else if(browserAgent != null && /(.*)chrome(.*)/.test(browserAgent)){
- browser = "chrome";
- }
- else if(browserAgent != null && /(.*)msie(.*)/.test(browserAgent)){
- browser = "msie";
- }
- else if(browserAgent != null && /(.*)mozilla(.*)/.test(browserAgent) && !/(.*)firefox(.*)/.test(browserAgent) && !/(.*)chrome(.*)/.test(browserAgent) && !/(.*)msie(.*)/.test(browserAgent)){
- browser = "safari";
- }
- return browser;
- }
- }
- }
热门文章推荐
- [HLS]做自己的m3u8点播系统使用HTTP Live Streaming(HLS技术)
- [FMS]FMS流媒体服务器配置与使用相关的介绍
- [AS3]什么是M3U8,与HTML5的区别是什么
- AS2.0 让flash自适应全屏,并且不自动缩放
- [AS3]as3.0的sound类常用技巧整理
- [AS3]as3与ByteArray详解、ByteArray介绍、ByteArray用法
- 关于RTMP,RTMPT,RTMPS,RTMPE,RTMPTE协议的介绍
- [JS]分享浏览器弹出窗口不被拦截JS示例
请稍候...