客户端中的GWT浏览器区别

oli*_*olz 5 java browser gwt user-agent

我尝试在GWT中找到特定Hack的当前浏览器.

喜欢:( 观景级)

if( GWT.getBrowserName().contains("IE") ) {
    // DOM.setElementPropertyBoolean( ...  Hack
}else {
    // normal stuff
}
Run Code Online (Sandbox Code Playgroud)

oli*_*olz 4

我找到了一个丑陋的解决方案:

为每个 Bowser 创建一个类并将其映射到gwt.xml

public class BrowserIE6 extends Browser {
    public boolean isIE6() { return true; }
    public boolean isIE7() { return false; }
    ...
}
Run Code Online (Sandbox Code Playgroud)

<replace-with class="com.project.client.style.BrowserIE6">
    <when-type-is class="com.project.client.style.Browser" />
    <when-property-is name="user.agent" value="ie6" />
</replace-with>

<replace-with class="com.project.client.style.BrowserIE7">
    <when-type-is class="com.project.client.style.Browser" />
    <when-property-is name="user.agent" value="ie7" />
</replace-with>

...
Run Code Online (Sandbox Code Playgroud)

但有没有一种简单的方法可以做到这一点呢?

  • 为什么不创建单独的“视图”类并使用延迟绑定来加载适合浏览器的视图? (2认同)