Frequently used javascript functions for Rust
and WebAssembly
webru
is a binding for web-sys
This crate assumes that you will only use this crate inside browser. Not any other javascript runtime such as Node.js
```rust
use wasmbindgen::closure::Closure; use wasmbindgen::JsCast; use websys::{Element, HtmlElement}; use weblog::consolelog; use webru::{alert, body, callback, createelement, getelementbyid, reload, set_timeout};
// javascript Window.alert()
method
alert("You are in danger!");
// getting the
tag/element let body: HtmlElement = body();// creating a
document.createElement()
method
// This function will return the newly created element/tag
let h1: Element = create_element("h1");
// adding some attributes to
id
property
h1.setclassname("heading"); // html class
property`
h1.setinner_html("Welcome to my website");
// pushing the
// This closure will be called the
// creating a
// adding some attributes to
cb.forget();
// pushing the
// javascript setTimeout()
method
settimeout(
|| {
// javascript console.log()
method
consolelog!("Time has completed");
// reload the page
// javascript `location.reload()` method
reload();
},
10000, // 10 seconds
);
// getting the
document.getElementById()
method
let h1fromdom: Optionasserteq!(h1from_dom.unwrap(), h1);
```