查找SWT浏览器的浏览器类型/版本 [英] Find browser type/version of SWT Browser
本文介绍了查找SWT浏览器的浏览器类型/版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遇到了Eclipse SWT浏览器无法在一台机器上加载某些样式的问题.我希望机器将IE 10用作本机浏览器,但是我不确定如何确认这一点.有没有办法确定SWT决定使用其加载页面的浏览器的类型/版本?
I am having problems with an Eclipse SWT Browser not loading certain styles on one machine. I am expecting the machine to use IE 10 as the native browser but I am not sure how I can confirm this. Is there a way to determine the type/version of the Browser which SWT decides to load the page using?
推荐答案
基于对此问题的公认答案:
Based on the accepted answer to this question:
您可以执行以下操作:
public static void main(String[] args)
{
final Display display = new Display();
final Shell shell = new Shell(display);
shell.setText("Stackoverflow");
shell.setLayout(new FillLayout());
Browser browser = new Browser(shell, SWT.NONE);
browser.addProgressListener(new ProgressListener()
{
@Override
public void changed(ProgressEvent progressEvent)
{
}
@Override
public void completed(ProgressEvent progressEvent)
{
System.out.println(browser.evaluate("var ua = navigator.userAgent, tem, 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 'IE ' + (tem[1] || ''); } if (M[1] === 'Chrome') { tem = ua.match(/\\b(OPR|Edge)\\/(\\d+)/); if (tem != null) return tem.slice(1).join(' ').replace('OPR', 'Opera'); } M = M[2] ? [M[1], M[2]] : [navigator.appName, navigator.appVersion, '-?']; if ((tem = ua.match(/version\\/(\\d+)/i)) != null) M.splice(1, 1, tem[1]); return M.join(' ');"));
}
});
browser.setUrl("https://www.google.co.uk");
shell.pack();
shell.open();
while (!shell.isDisposed())
{
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
在我的情况下它输出IE 11
.
这篇关于查找SWT浏览器的浏览器类型/版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文