Description: Returns the width of the browser or iFrame the app is in. On a desktop web browser this means the width of the entire window (including scrollbars), while on a mobile device it is the width of the devices screen.
________________________________________
SYNTAX:
foo = browser_width;
foo:
TYPE: INTEGER
The width of the browser or iFrame.
________________________________________
REMARKS:
CAUTION: Don't get browser_width confused with window_get_width()! The two are completely different. browser_width returns the width of the browser window, and as confusing as it sounds, window_get_width() returns the width of the canvas element.
TIP: It's easier to understand the difference in the following way. Imagine that the web browser is your desktop. In this case the "window" would be the canvas element.
________________________________________
WHERE:
You can check the browser width pretty much anywhere you'd like in your code. You can use it in the Create Event to prepare the size of the canvas or room. You could also use it in the step/draw event as a check to make sure that the browser is above a certain size and let the user know that the browser is too small for the app to display properly.
________________________________________
WHEN:
You should check the browser size whenever you need to resize or move the canvas. This will ensure you keep the canvas inside the browser, and if not alert the user.
________________________________________
EXAMPLE:
One way of using browser_width and browser_height would be to display a message if the browser is too small for the app to be displayed correctly. You can do this by using something like:
[code=auto:0]if (browser_width < 600 or browser_height < 400){
draw_set_color(c_red);
draw_text(0,0,'Please resize your browser to view the game properly!');
}[/ code]
WARNING: Be very careful that you display a message as text, and NOT using show_message(), as you risk trapping the user with an endless stream of messages!
________________________________________
DEMO:
http://afoobar.com/foo/gmdn/gml/yoyo-functions/browser-size
________________________________________
SEE ALSO:
- browser_height
- window_get_height()
- window_get_width()
________________________________________
ABOUT THE AUTHOR:

I've been coding since I was in the 5th grade on and off. In the 15 years since, I've worked on a number of GameMaker projects to include: an AI Chatbot, an interface for Lego Mindstorms to add computer controlled intelligence to the robots, several prototype applications (one commercial), a data compressor for the Lobner Prize (didn't even close though lol), and a network monitor that was actually used in my battalion while serving in Iraq! As a prototyping tool I firmly believe GameMaker cannot be beat, and know from first hand experience that "Game"Maker can do much more than just make games.
This belief is what has led me to create this site. With the release of GMHTML5 I strongly believe that if YoYoGames plays their cards right, GMTHML5 could shape the way people interact with the web through it's accessibility, active community, and the huge database of scripts and resources due to how long GameMaker has been around. I believe that the GMDN will help make GMHTML5 that much more accessible to the hobbyist who may have great ideas but lack the know-how to carry them out. I believe that with enough patience, fortitude, and a bit of luck the GameMaker Community as a whole can take GMHTML5, and the web experience, to a whole new level!
This is why I am so passionate about helping to create a GMHTML5 encyclopedic database for the GameMaker Community.
This is why I stay up late and wake up early to fit in a few extra minutes of code.
This is why I will continue to do so...
Follow me on
Twitter.