Search code examples
javawebviewjavafxjava-7javafx-webengine

JavaFx Webview goes to mobile site -(using jdk 7)


I am trying to create a JavaFX desktop application which consists of an embedded browser.

webEngine.load("http://sampleurl");

This statment loads the mobile website for some sites and for some others it loads the desktop site. Is this because of JavaFX or the implementation of the respective websites?

Morever the view is exactly same as IE. Is it possible to change it to chrome or mozilla? I am using jdk 7.


Solution

  • According to an comment an this question's answer. You should be able to set a user agent for your Weview with webEngine.setUserAgent(USER_AGENT_STRING).
    It seems to need JDK8 though. Indeed the JavaFX 2.2 javadoc doesn't contain it, though the JavaFX 8 one does.

    You may be able to fake something like a Windows Chrome Browser with a user agent string like this one:
    Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36

    If you really need to use JDK7, you may be stuck here. Setting the JVM's user agent may be sufficient, but probably it will use an internal user agent.