Hybrid Deployment: WebGL & Unity Web Player

I’m in the midst of developing a small game for Facebook and would like to setup an HTML file that will serve Chrome users the WebGL version of the game and the Unity Web Player version of the game to all other browsers. In the documentation for the most recent beta version of the Facebook SDK for Unity (v7.0.2), they suggest using something like the following:

<!DOCTYPE html>
<html>
<body>
<script>

var chromeVersion = window.navigator.userAgent.match(/Chrome\/(\d+)\./);
if (chromeVersion && chromeVersion[1]) {
  if (parseInt(chromeVersion[1], 10) >= 42) {
    window.location = "/games/webGL";
  }
}
window.location = "/games/game.html";

</script>
</body>
</html>

Unfortunately, this still loads the “game.html” file in Chrome, which isn’t at all what I had expected. I was hoping someone here might be able to suggest how to properly format the HTML file in order to properly split the two versions between different browsers. If you’ve any suggestions, I’d most certainly appreciate hearing them. Thanks!

var chromeVersion = window.navigator.userAgent.match(/Chrome\/(\d+)\./);
var useWebGL = false;

useWebGL |= chromeVersion && chromeVersion[1] && parseInt(chromeVersion[1], 10) >= 42;

if (useWebGL)
    window.location = "/games/webGL";
else
    window.location = "/games/game.html";

You were overriding the location everytime since it was outside the if scope.

1 Like

facepalm I totally should have caught that, haha. Been pulling too many long nights/days lately I think. I wonder what Facebook’s excuse is, lol :stuck_out_tongue: I’ve sent them a message indicating the location of the error. Thanks so much!