Skip to content

Instantly share code, notes, and snippets.

@jgphilpott
Last active September 13, 2023 14:00
Show Gist options
  • Save jgphilpott/68e9e22ea6ac5bf44ff7a86ef75b5e5d to your computer and use it in GitHub Desktop.
Save jgphilpott/68e9e22ea6ac5bf44ff7a86ef75b5e5d to your computer and use it in GitHub Desktop.
A helpful interface for the window location object.
# Credit: https://www.w3schools.com/js/js_window_location.asp
class Page
constructor: ->
@url = window.location
href: ->
return this.url.href
protocol: ->
return this.url.protocol
host: ->
return this.url.hostname
path: ->
return this.url.pathname
port: ->
return this.url.port
redirect: (href = "") ->
return this.url.assign href
// Credit: https://www.w3schools.com/js/js_window_location.asp
var Page;
Page = class Page {
constructor() {
this.url = window.location;
}
href() {
return this.url.href;
}
protocol() {
return this.url.protocol;
}
host() {
return this.url.hostname;
}
path() {
return this.url.pathname;
}
port() {
return this.url.port;
}
redirect(href = "") {
return this.url.assign(href);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment