簡體   English   中英

查找SWT瀏覽器的瀏覽器類型/版本

[英]Find browser type/version of SWT Browser

我遇到Eclipse SWT瀏覽器無法在一台機器上加載某些樣式的問題。 我期待機器使用IE 10作為本機瀏覽器,但我不知道如何確認這一點。 有沒有辦法確定SWT決定使用加載頁面的瀏覽器的類型/版本?

基於對此問題的接受答案:

如何檢測瀏覽器的版本?

你可以這樣做:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM