Add a top-level web_sys::window function

Returns `Option<Window>` and can be used as a convenience to get a handle to the
global `window` object.
This commit is contained in:
Alex Crichton
2018-09-17 14:25:04 -07:00
parent 99e1b352e5
commit f24828a16b
5 changed files with 19 additions and 4 deletions

View File

@ -8,7 +8,7 @@ use wasm_bindgen::JsCast;
#[wasm_bindgen]
pub fn draw() {
let document = web_sys::Window::document().unwrap();
let document = web_sys::window().unwrap().document().unwrap();
let canvas = document.get_element_by_id("canvas").unwrap();
let canvas: web_sys::HtmlCanvasElement = canvas
.dyn_into::<web_sys::HtmlCanvasElement>()