Last active
September 13, 2023 14:00
-
-
Save jgphilpott/68e9e22ea6ac5bf44ff7a86ef75b5e5d to your computer and use it in GitHub Desktop.
A helpful interface for the window location object.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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