sixtyfootersdude
sixtyfootersdude

Reputation: 27241

GWT 2.7: Warn users they are using an unsupported browser

I recently upgraded my application to GWT 2.7 from GWT 2.5. This has caused me to drop support for IE6 and IE7.

I would like to provide users with IE6 or IE7 with a warning that their browser is outdated and will not work. At the moment if you go to the app with one of those browsers, you get a blank screen.

I know there are a couple ways that I could hack something together but I would rather use the GWT way, rather than some hack. Is there a GWT hook for unsupported browsers?

Option (hack) One

Drop this into my main.html:

if(document.documentMode === 6 || document.documentMode === 7){
    myUnsupportedBrowserWarningFunction();
}

Potential problem with this is that if someone is using a browser that GWT doesn't recognise and I don't recognise (mobile opera? Some other browser), they will still get a blank page.

Option (hack) Two

GWT looks for the compiled JS here:

gwt/myApp/ASDFKLSDJFLSFDJSLDFJLSJDFSDES.cache.js

When someone is using an unsupported browser the following is requested (and is not found):

gwt/myApp/undefined.cache.js

It would be possible to create undefined.cache.js and put your unsupported browser code there. This is obviously a brittle solution and will break with future GWT updates.

Option Three

A recent patch (available in GWT 2.7) allows you to provide a default permutation (e.g. safari) if GWT can not detect the browser and with deferred binding you can display a warning that the provided app might not work correctly as the browser is generally unsupported by GWT.

-- J.

Source

I don't want to set a default permutation for unsupported browsers. I want the site to not work and to display a warning. So this solution doesn't really provide what I am looking for.

Similar Questions & Posts

Upvotes: 0

Views: 1170

Answers (2)

Thomas Broyer
Thomas Broyer

Reputation: 64561

You should be able to use onLoadErrorFn for that: https://code.google.com/p/google-web-toolkit/issues/detail?id=8135

<script>
  function gwtLoadError(errMsg) {
    // GWT app couldn't load, reason in errorMsg
  }
</script>
<meta name="gwt:onLoadErrorFn" content="gwtLoadError">

or possibly onPropertyErrorFn:

<script>
  function gwtPropError(propName, allowedValues, actualValue) {
    if (propName == 'user.agent') {
      // unsupported browser
    }
  }
</script>
<meta name="gwt:onPropertyErrorFn" content="gwtPropError">

(I don't think user.agent.runtimeWarning would help in this case, but maybe have a look)

Upvotes: 2

Christian Kuetbach
Christian Kuetbach

Reputation: 16060

There is an easy way:

Conditional Comments

<!--[if lt IE 8]>
<p>You are using an unsupportet browser. Please perform an update</p>
<![endif]-->

I think Option 3 may be the best one, but there is a problem: This will start the actual application (which still may be incompatible).

If this is an issue and you want a clear warning, you can rewrite the permutation selection script (You would need to update the script with the upcoming GWT releases)

You will need to copy this source:

https://gwt.googlesource.com/gwt/+/2.7.0/user/src/com/google/gwt/useragent/rebind/UserAgentPropertyGenerator.java

You could add something like:

$wnd.Location.replace('nosupported.html');

between line 90 and 91

Upvotes: -1

Related Questions