Parcourir la source

add js.Browser.supported

Simon Krajewski il y a 11 ans
Parent
commit
f9bcb4b12a
1 fichiers modifiés avec 9 ajouts et 0 suppressions
  1. 9 0
      std/js/Browser.hx

+ 9 - 0
std/js/Browser.hx

@@ -37,6 +37,15 @@ class Browser {
 	public static var navigator(get, never):js.html.Navigator;
 	inline static function get_navigator() return untyped __js__("window.navigator");
 	
+	/**
+	 * True if a window object exists, false otherwise.
+	 *
+	 * This can be used to check if the code is being executed in a non-browser
+	 * environment such as node.js.
+	 */
+	public static var supported(get, never):Bool;
+	public static function get_supported() return untyped __js__("typeof window != \"undefined\"");
+	
 	/**
 	 * Safely gets the browser's local storage, or returns null if localStorage is unsupported or
 	 * disabled.