How to adjust gameContainer size with a JS function?

Edit: When I change the height and width of gameContainer, ONLY the dark container background changes size. The game itself remains the old size. See picture attached to bottom post.

mergeInto(LibraryManager.library, {

  Hello: function () {
    alert("Hello, world!");
  },

  CheckForMobile: function () {
    return UnityLoader.SystemInfo.mobile;
  },

  SetContainerSize: function () {
    document.getElementById("gameContainer").style.width = "400px";
    document.getElementById("gameContainer").style.height = "720px";
  },


});

I want SetContainerSize to change the gameContainer size. I will call the function within the Unity game. However, this does not work:
document.getElementById(‘gameContainer’).style.height = ‘50px’;
It gives me a build error message.
Any help much appreciated, thank you!

looks like the two quotes are not consistent. try with double quotes instead: “50px”

1 Like

Really?! Disadvantage of working on a Mac…

Can I also do double quotes around gameContainer?

  SetContainerSize: function () {
    document.getElementById("gameContainer").style.height = "50px";
  },

Thank you for taking the time to reply and help out, that’s really awesome. :slight_smile:

Edit: No build error! :slight_smile:

Hm, so it doesn’t change the size of the game. It creates a white space ABOVE the game.
I’m using the standard WebGL template (with the full screen button in the bottom-right corner).
Maybe the code needs to be different? Do I also need to alter something in the game itself?
Basically I want to change the height and width dimensions of the gameContainer from landscape to portrait if the player clicks on a button in the game.

document.getElementById("gameContainer").style.width = "400px";
document.getElementById("gameContainer").style.height = "700px";

This seems to work. Still trying…

This is what happens…

It works! Thank you SOOOO much! :slight_smile: