Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 150877 Details for
Bug 293736
[Browser] Add Browser.getBrowserVersion()
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
A Javascript based approach.
JSBrowserDetection.java (text/java), 4.03 KB, created by
Christopher Deckers
on 2009-10-29 17:07:53 EDT
(
hide
)
Description:
A Javascript based approach.
Filename:
MIME Type:
Creator:
Christopher Deckers
Created:
2009-10-29 17:07:53 EDT
Size:
4.03 KB
patch
obsolete
>/* > * Christopher Deckers (chrriis@nextencia.net) > * http://www.nextencia.net > * > * See the file "readme.txt" for information on usage and redistribution of > * this file, and for a DISCLAIMER OF ALL WARRANTIES. > */ >package test; > >import org.eclipse.swt.browser.Browser; >import org.eclipse.swt.layout.FillLayout; >import org.eclipse.swt.widgets.Shell; > >/** > * @author Christopher Deckers > */ >class JSBrowserDetection { > > public final String browserName; > public final String browserVersion; > > public JSBrowserDetection(Browser browser) { > Shell shell = new Shell(browser.getDisplay()); > shell.setLayout(new FillLayout()); > Browser browser_ = new Browser(shell, browser.getStyle()); > browser_.setText("<html></html>"); > String browserName = null; > String versionSearch = null; > String userAgent = (String)browser_.evaluate("return navigator.userAgent"); > String navigatorVendor = (String)browser_.evaluate("return navigator.vendor"); > if(browserName == null && userAgent != null && userAgent.indexOf("Chrome") != -1) { > versionSearch = browserName = "Chrome"; > } > if(browserName == null && userAgent != null && userAgent.indexOf("OmniWeb") != -1) { > browserName = "OmniWeb"; > versionSearch = "OmniWeb/"; > } > if(browserName == null && navigatorVendor != null && navigatorVendor.indexOf("Apple") != -1) { > browserName = "Safari"; > // "Version" is probably more user friendly but is not always accessible. > versionSearch = "AppleWebKit"; > } > if(browserName == null && (String)browser_.evaluate("return window.opera") != null) { > versionSearch = browserName = "Opera"; > } > if(browserName == null && navigatorVendor != null && navigatorVendor.indexOf("iCab") != -1) { > versionSearch = browserName = "iCab"; > } > if(browserName == null && navigatorVendor != null && navigatorVendor.indexOf("KDE") != -1) { > versionSearch = browserName = "Konqueror"; > } > if(browserName == null && userAgent != null && userAgent.indexOf("Firefox") != -1) { > versionSearch = browserName = "Firefox"; > } > if(browserName == null && navigatorVendor != null && navigatorVendor.indexOf("Camino") != -1) { > versionSearch = browserName = "Camino"; > } > if(browserName == null && userAgent != null && userAgent.indexOf("Netscape") != -1) { > versionSearch = browserName = "Netscape"; > } > if(browserName == null && userAgent != null && userAgent.indexOf("MSIE") != -1) { > browserName = "IE"; > versionSearch = "MSIE"; > } > if(browserName == null && userAgent != null && userAgent.indexOf("Gecko") != -1) { > browserName = "Mozilla"; > versionSearch = "rv"; > } > if(browserName == null && userAgent != null && userAgent.indexOf("Mozilla") != -1) { > browserName = "Netscape"; > versionSearch = "Mozilla"; > } > String browserVersion = null; > if(browserName != null) { > if(userAgent != null) { > int index = userAgent.indexOf(versionSearch); > if(index >= 0) { > browserVersion = userAgent.substring(index + versionSearch.length() + 1); > } > } > if(browserVersion == null) { > String appVersion = (String)browser_.evaluate("return navigator.appVersion"); > if(appVersion != null) { > int index = appVersion.indexOf(versionSearch); > if(index >= 0) { > browserVersion = appVersion.substring(index + versionSearch.length() + 1); > } > } > } > if(browserVersion != null) { > int index = -1; > for(int i=0; i<browserVersion.length(); i++) { > char c = browserVersion.charAt(i); > if(!Character.isDigit(c) && c != '.' && c != '_' && c != '-' && (c < 'a' || c > 'z') && c < 'A' && c < 'Z') { > index = i; > break; > } > } > if(index > 0) { > browserVersion = browserVersion.substring(0, index); > } > } > } > this.browserName = browserName; > this.browserVersion = browserVersion; > } > >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 293736
: 150877