1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use webcore::value::Reference;
use webcore::try_from::TryInto;
/// The `Location` interface represents the location (URL) of the object it
/// is linked to. Changes done on it are reflected on the object it relates
/// to. Both the [Document](struct.Document.html) and [Window](struct.Window.html)
/// interface have such a linked `Location`, accessible via [Document::location](struct.Document.html#method.location)
/// and [Window::location](struct.Window.html#method.location) respectively.
///
/// [(JavaScript docs)](https://developer.mozilla.org/en-US/docs/Web/API/Location)
pub struct Location( Reference );
reference_boilerplate! {
Location,
instanceof Location
}
impl Location {
/// The entire URL.
///
/// [(JavaScript docs)](https://developer.mozilla.org/en-US/docs/Web/API/Location/href)
pub fn href( &self ) -> String {
js!(
return @{self}.href;
).try_into().unwrap()
}
/// Returns a `String` containing a '#' followed by the fragment
/// identifier of the URL. The fragment is not percent-decoded.
///
/// [(JavaScript docs)](https://developer.mozilla.org/en-US/docs/Web/API/Location/hash)
pub fn hash( &self ) -> String {
js!(
return @{self}.hash;
).try_into().unwrap()
}
}